RexesOperator
Registered User.
- Local time
- Today, 11:06
- Joined
- Jul 15, 2006
- Messages
- 604
Something really weird is going on. This is Access 2003.
I have a procedure that uploads from Access to Excel. The button is on the main form frmTransactions, but the information being uploaded is on a subform frmTransactionsQe. The subform control is ctlQeSites.
I have a number of text boxes on the form. One is txtSITEID, the next is txtSITENAME etc. When I click on the Upload button I created, Excel is called up. The first time I run the procedure the correct value will be loaded into the appropriate cell. Say - txtSITENAME's contents will be transferred to "B9". The next time it is run, I get the Application-Defined error. When I check the code - the name of the text box has been changed.
objXLBook.ActiveSheet.Range("B9") = Forms!frmTransactionsMain.ctlQeSites.Form.txtUTMNORTH
should be
objXLBook.ActiveSheet.Range("B9") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITENAME
It looks like the code is stepping through to the next text box - except that isn't the next one in the tab view, so I don't know where it is getting the item from.
I have tried compact and repair, as well as importing everything to a new db. I have also tried commenting out all but one of the lines of code to see if this affecting more than just the first one - it is. I have also attached the original procedure BEFORE I ran it, and an image of the form design to show I am using the correct text box name. I have tried the db on different notebooks. I have tried deleting the text box from the form and creating a new one. I have tried other text boxes to see if they would load, and they didn't. However - the exact same code works in an earlier version of this db - on both notebooks
Here is the procedure:
Private Sub cmdUpLoadQetoExcel_Click()
On Error GoTo Err_OpenExcelFile_Click
Dim objXLApp As Object
Dim objXLBook As Object
Set objXLApp = CreateObject("Excel.Application")
Set objXLBook = objXLApp.Workbooks.Open("C:\Q11.xls")
objXLApp.Visible = True
objXLApp.UserControl = True
objXLBook.ActiveSheet.Range("B9") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITENAME
objXLBook.ActiveSheet.Range("B10") = Forms!frmTransactionsMain.ctlQeSites.Form.cboSITEPROVINCE
objXLBook.ActiveSheet.Range("B11") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELATDEG
objXLBook.ActiveSheet.Range("B12") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELATMIN
objXLBook.ActiveSheet.Range("B13") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELATSEC
objXLBook.ActiveSheet.Range("B14") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELONDEG
objXLBook.ActiveSheet.Range("B15") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELONMIN
objXLBook.ActiveSheet.Range("B16") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELONSEC
objXLBook.ActiveSheet.Range("B17") = Forms!frmTransactionsMain.ctlQeSites.Form.txtELEVATION
objXLBook.ActiveSheet.Range("B18") = Forms!frmTransactionsMain.ctlQeSites.Form.txtTOWERHT
Exit_OpenExcelFile_Click:
Exit Sub
Err_OpenExcelFile_Click:
MsgBox Err.Description
Resume Exit_OpenExcelFile_Click
End Sub
There are no spaces in the code - that is the forum thing again.
I have a procedure that uploads from Access to Excel. The button is on the main form frmTransactions, but the information being uploaded is on a subform frmTransactionsQe. The subform control is ctlQeSites.
I have a number of text boxes on the form. One is txtSITEID, the next is txtSITENAME etc. When I click on the Upload button I created, Excel is called up. The first time I run the procedure the correct value will be loaded into the appropriate cell. Say - txtSITENAME's contents will be transferred to "B9". The next time it is run, I get the Application-Defined error. When I check the code - the name of the text box has been changed.
objXLBook.ActiveSheet.Range("B9") = Forms!frmTransactionsMain.ctlQeSites.Form.txtUTMNORTH
should be
objXLBook.ActiveSheet.Range("B9") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITENAME
It looks like the code is stepping through to the next text box - except that isn't the next one in the tab view, so I don't know where it is getting the item from.
I have tried compact and repair, as well as importing everything to a new db. I have also tried commenting out all but one of the lines of code to see if this affecting more than just the first one - it is. I have also attached the original procedure BEFORE I ran it, and an image of the form design to show I am using the correct text box name. I have tried the db on different notebooks. I have tried deleting the text box from the form and creating a new one. I have tried other text boxes to see if they would load, and they didn't. However - the exact same code works in an earlier version of this db - on both notebooks
Here is the procedure:
Private Sub cmdUpLoadQetoExcel_Click()
On Error GoTo Err_OpenExcelFile_Click
Dim objXLApp As Object
Dim objXLBook As Object
Set objXLApp = CreateObject("Excel.Application")
Set objXLBook = objXLApp.Workbooks.Open("C:\Q11.xls")
objXLApp.Visible = True
objXLApp.UserControl = True
objXLBook.ActiveSheet.Range("B9") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITENAME
objXLBook.ActiveSheet.Range("B10") = Forms!frmTransactionsMain.ctlQeSites.Form.cboSITEPROVINCE
objXLBook.ActiveSheet.Range("B11") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELATDEG
objXLBook.ActiveSheet.Range("B12") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELATMIN
objXLBook.ActiveSheet.Range("B13") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELATSEC
objXLBook.ActiveSheet.Range("B14") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELONDEG
objXLBook.ActiveSheet.Range("B15") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELONMIN
objXLBook.ActiveSheet.Range("B16") = Forms!frmTransactionsMain.ctlQeSites.Form.txtSITELONSEC
objXLBook.ActiveSheet.Range("B17") = Forms!frmTransactionsMain.ctlQeSites.Form.txtELEVATION
objXLBook.ActiveSheet.Range("B18") = Forms!frmTransactionsMain.ctlQeSites.Form.txtTOWERHT
Exit_OpenExcelFile_Click:
Exit Sub
Err_OpenExcelFile_Click:
MsgBox Err.Description
Resume Exit_OpenExcelFile_Click
End Sub
There are no spaces in the code - that is the forum thing again.
Attachments
Last edited: