
I think I am very close to getting Access to load data from a form into a spreadsheet, but I am missing something.
The code below should load the field NAME into cell B9.
After doing some more research, I have this cobbled together this code for two command buttons - OpenExcelFile and LoadInfo. The first button should open the excel file Q11. It does.
The second button should load the data from the Access form into the worksheet. I am getting a runtime error '424' "Object required".
I think I need to identify the worksheet (Tombstone Data) in the workbook. How do I do that?
Private Sub OpenExcelFile_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
Exit_OpenExcelFile_Click:
Exit Sub
Err_OpenExcelFile_Click:
MsgBox Err.Description
Resume Exit_OpenExcelFile_Click
End Sub
Private Sub LoadInfo_Click()
Dim objXLApp As Object
Dim objXLBook As Object
Set objXLApp = CreateObject("Excel.Application")
Set objXLBook = objXLApp.Workbooks.Open("C:\Q11.xls")
objExcelBook.ActiveSheet.Range("B9") = Me.NAME
End Sub
This is thanks to some code borrowed from Bob Larson in another forum