I have people on Access 2010 and 2013. I've tried to change my code to late binding to avoid the missing reference, but it's I'm still getting the missing reference. Where did I go wrong? Thanks in advance.
Code:
Private Sub sendquotes_Click()
' Excel constants:
Const strcXLPath As String = "C:\Users\amw\AppData\Roaming\Microsoft\Templates\Sales Pipeline Quote Report.xltx"
Const strcWorksheetName As String = "Sales Pipeline Quote Report"
Const strcCellAddress As String = "A5"
' Access constants:
Const strcQueryName As String = "q_SalesPipeLineQuotesCurMo"
' Excel Objects:
Dim objXL As Object ' Excel.Application
Dim objWBK As Object ' Excel.Workbook
Dim objWS As Object ' Excel.Worksheet
Dim objRNG As Object ' Excel.Range
' DAO objects:
Dim objDB As DAO.Database
Dim objQDF As DAO.QueryDef
Dim objrs As DAO.Recordset
Dim objQDFT As DAO.QueryDef
Dim objQDFW As DAO.QueryDef
On Error GoTo Error_Exit_SaveRecordsetToExcelRange
' Open a DAO recordset on the query:
Set objDB = CurrentDb()
Set objQDF = objDB.QueryDefs(strcQueryName)
Set objrs = objQDF.OpenRecordset
' Open Excel and point to the cell where
' the recordset is to be inserted:
' Set objXL = New Excel.Application
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
Set objWBK = objXL.Workbooks.Open(strcXLPath)
Set objWS = objWBK.Worksheets(strcWorksheetName)
With objWS
.Cells(1, 2).Value = DateSerial(Year(Date), Month(Date), 1)
.Cells(2, 2).Value = DateSerial(Year(Date), Month(Date) + 1, 1 - 1)
End With
Set objRNG = objWS.Range(strcCellAddress)
objRNG.CopyFromRecordset objrs
' Destroy objects:
GoSub CleanUp
Exit_SaveRecordsetToExcelRange:
Exit Sub
CleanUp:
' Destroy Excel objects:
Set objRNG = Nothing
Set objWS = Nothing
Set objWBK = Nothing
Set objXL = Nothing
' Destroy DAO objects:
If Not objrs Is Nothing Then
objrs.Close
Set objrs = Nothing
End If
Set objQDF = Nothing
Set objDB = Nothing
Return
Error_Exit_SaveRecordsetToExcelRange:
MsgBox "Error " & Err.Number _
& vbNewLine & vbNewLine _
& Err.Description, _
vbExclamation + vbOKOnly, _
"Error Information"
GoSub CleanUp
Resume Exit_SaveRecordsetToExcelRange
End Sub
Last edited by a moderator: