tc8224 Posted April 17, 2006 Posted April 17, 2006 (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.ApplicationDim xlBook As Excel.WorkbookDim xlSheet As Excel.WorksheetDim rstRunInfo As New ADODB.RecordsetDim rstRunInfo2 As New ADODB.RecordsetDim strDate As DateDim strCustomer As StringDim strLast As StringDim strDesc As StringDim strPet As StringDim strType As StringDim introwcounter As IntegerDim WorkBookFilePath As StringWorkBookFilePath = "C:\Documents and Settings\tc\Desktop\Final Project\Appointment.xls"Set appexcel = New Excel.ApplicationSet 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").ActivateDointrowcounter = introwcounter + 1Loop 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 WithrstRunInfo.Open "Customers", CurrentProject.Connection, adOpenStaticWith rstRunInfoDo While (Not .EOF) strCustomer = .Fields("Customer Name") With xlSheet.Rows(introwcounter) cmbCustomerName.SetFocus .Cells(6, 1).Value = cmbCustomerName.TextEnd With .MoveNextLoopEnd WithrstRunInfo2.Open "Pets", CurrentProject.Connection, adOpenStaticWith rstRunInfo2Do 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 = txtDescriptionEnd With.MoveNextLoopEnd WithWith xlSheet.Rows(1) .Font.Bold = True .Font.Size = 14End WithColumns("A:H").AutoFitMsgBox "Your Appointment Has Been Recorded!", vbInformation, "Appointment Recorded"cmbCustomerName = ""cmbName = ""cmbType = ""txtDescription = ""appexcel.Visible = TrueEnd Sub Edited April 17, 2006 by tc8224
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now