Jump to content

Recommended Posts

Posted (edited)

This is really making me mad. What I'm trying to do is, when you click on "Emergency Appointments" and click "NO" on the Question Box, you can click the combo boxes, and click an option button, It will then open the "Appointment".xls file, and then insert the info from this sheet, and it will select the correct worksheet which is determined from the option buttons. And then if you add new data from the "OldAppointments" form, it will add the data to the worksheets, and not open a new copy of the file.

Here is the code........

Private Sub cmdSubmit_Click()

Dim appexcel As Excel.Application

Dim xlBook As Excel.Workbook

Dim xlSheet As Excel.Worksheet

Dim rstRunInfo As New ADODB.Recordset

Dim rstRunInfo2 As New ADODB.Recordset

Dim strDate As Date

Dim strCustomer As String

Dim strLast As String

Dim strDesc As String

Dim strPet As String

Dim strType As String

Dim introwcounter As Integer

Dim WorkBookFilePath As String

WorkBookFilePath = "C:\Documents and Settings\tc\Desktop\Final Project\Appointment.xls"

Set appexcel = New Excel.Application

Set xlBook = Workbooks.Open(WorkBookFilePath)

'appExcel.Workbooks.Add

'Set xlBook = appExcel.Workbooks(1)

'Set xlSheet = xlBook.Worksheets(1)

Set xlSheet = xlBook.Sheets("Tuesday")

Set cmbDays = ("xlSheet")

'Worksheets("Tuesday").Activate

Do

introwcounter = introwcounter + 1

Loop Until Cells(introwcounter, 1) = ""

'Cells(introwcounter, 1) = cmbCustomerName

'Cells(introwcounter, 3) = cmbName

'Cells(introwcounter, 4) = cmbType

'Cells(introwcounter, 6) = txtDescription

'With xlSheet.Rows(1)

' .Cells(1).Value = "Customer Name"

' .Cells(3).Value = "Pet Name"

'.Cells(4).Value = "Pet Type"

' .Cells(6).Value = "Description"

'End With

rstRunInfo.Open "Customers", CurrentProject.Connection, adOpenStatic

With rstRunInfo

Do While (Not .EOF)

strCustomer = .Fields("Customer Name")

With xlSheet.Rows(introwcounter)

cmbCustomerName.SetFocus

.Cells(6, 1).Value = cmbCustomerName.Text

End With

.MoveNext

Loop

End With

rstRunInfo2.Open "Pets", CurrentProject.Connection, adOpenStatic

With rstRunInfo2

Do While (Not .EOF)

cmbName = .Fields("Pet Name")

cmbType = .Fields("Pet Type")

With xlSheet.Rows(introwcounter)

.Cells(6, 3).Value = cmbName

.Cells(6, 4).Value = cmbType

.Cells(6, 6).Value = txtDescription

End With

.MoveNext

Loop

End With

With xlSheet.Rows(1)

.Font.Bold = True

.Font.Size = 14

End With

Columns("A:H").AutoFit

MsgBox "Your Appointment Has Been Recorded!", vbInformation, "Appointment Recorded"

cmbCustomerName = ""

cmbName = ""

cmbType = ""

txtDescription = ""

appexcel.Visible = True

End Sub

Edited by tc8224

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...