Hello, I'm hoping someone can help. We just upgraded to Access 2007 and I have a database that is still in native 2003 that I'm getting a "runtime 424 object required" error message on a particular report that exports into excel. I'm not sure what is different in 2007 vs. 2003 but this code is not working in 2007. If I click through all of the 'end' messages, the excel spreadsheet does eventually come up with the correct data.
Below is the code, which I didn't not create so I'm flying a little blind:
Public Function fExportReportInfoToExcel(strFilterDate As Variant, strFilterPlant As Variant, _
strFilterDepartment As Variant, strFilterLine As Variant, strFilterMaterial As Variant, _
strFilterShift As Variant, strFilterTargetWtRange As Variant, strFilterTechnician As Variant, _
strReportHeader As Variant, strYAxis As Variant, RsSql As Variant, _
strFilterFinishBatchNo As String, strFilterWtCtrlFrmNo As String) '091604 KLK new Finished Batch Number upgrade. Added strFilterFinishBatchNo , strFilterWtCtrlFrmNo
Dim DB As DAO.Database, Rs As DAO.Recordset
Dim i As Integer, J As Integer
'RsSql = recordset query string
Dim CurrentValue As Variant
Dim CurrentField As Variant
Dim Workbook As Object
Dim xlApp As Object
Dim Sheet As Object
Set DB = DBEngine.Workspaces(0).Databases(0)
Set Rs = DB.OpenRecordset(RsSql, dbOpenDynaset)
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Add
Set Sheet = xlApp.Workbooks.Open(strExcelSpreadsheet, , True).Sheets("data")
J = 1
Sheet.Cells(11, 6).Value = 2 '
' Loop through the Microsoft Access field names and create
' the Microsoft Excel labels.
For i = 0 To Rs.Fields.Count - 1
CurrentValue = Rs.Fields(i).Name
Sheet.Cells(J, i + 1).Value = CurrentValue
Next i
J = 2
' Loop through the Microsoft Access records and copy the records
' to the Microsoft Excel spreadsheet.
Do Until Rs.EOF
For i = 0 To Rs.Fields.Count - 1
CurrentField = Rs(i)
Sheet.Cells(J, i + 1).Value = CurrentField
Next i
Rs.MoveNext
J = J + 1
Loop
' Put the value of the ToExcel text box into the cell on the
' spreadsheet and make the cell bold.
strFilterDate = "'" & strFilterDate
Sheet.Cells(1, 6).Value = strFilterDate
Sheet.Cells(2, 6).Value = strFilterPlant
Sheet.Cells(3, 6).Value = strFilterDepartment
Sheet.Cells(4, 6).Value = strFilterLine
Sheet.Cells(5, 6).Value = strFilterMaterial
Sheet.Cells(6, 6).Value = strFilterShift
Sheet.Cells(7, 6).Value = strFilterTargetWtRange
Sheet.Cells(8, 6).Value = strFilterTechnician
Sheet.Cells(9, 6).Value = strReportHeader
Sheet.Cells(10, 6).Value = strYAxis
Sheet.Cells(11, 6).Value = J - 1 '
'091604 KLK new start Finished Batch Number upgrade.
Sheet.Cells(12, 6).Value = strFilterFinishBatchNo
Sheet.Cells(13, 6).Value = strFilterWtCtrlFrmNo '
'091604 KLK new end Finished Batch Number upgrade.
xlApp.Worksheets("Print Out").Range("A1").Activate
' Print the Microsoft Excel spreadsheet.
Sheet.Application.Visible = True
' cleanup.
Set Sheet = Nothing
Set xlApp = Nothing
End Function'
Thanks in advance.
The runtime error is coming in at the code that is red above.
PJ