I am trying to export some data to Excel using some code I found:
Private Sub cmdExcelExport_Click()
Dim strXL_Location As String
Dim cdb As DAO.Database, qdf As DAO.QueryDef
Const tempTableName = "_tempTbl"
Set cdb = CurrentDb
strXL_Location = "X:\Access Database\Spreadsheets\test.xlsx"
On Error Resume Next
DoCmd.DeleteObject acTable, tempTableName
On Error GoTo 0
Set qdf = cdb.CreateQueryDef("")
qdf.SQL = "SELECT * INTO [" & tempTableName & "] FROM [tblStockLogin]"
qdf.Parameters("Box").Value = "AR1N"
qdf.Execute
Set qdf = Nothing
Set cdb = Nothing
DoCmd.OutputTo acOutputTable, tempTableName, acFormatXLSX, strXL_Location, True
End Sub
But this causes the error 3265 on the line:
qdf.Parameters("Box").Value = "AR1N"
I have:
Checked that tblStockLogin is spelled correctly
Checked that Box field exist
Remove the parameters line and it works correctly (ie brings ALL data back from the tblStockLogin table)
I am a newbie (both in Access and in using Forums) but I cannot find an answer (that works for me).
Private Sub cmdExcelExport_Click()
Dim strXL_Location As String
Dim cdb As DAO.Database, qdf As DAO.QueryDef
Const tempTableName = "_tempTbl"
Set cdb = CurrentDb
strXL_Location = "X:\Access Database\Spreadsheets\test.xlsx"
On Error Resume Next
DoCmd.DeleteObject acTable, tempTableName
On Error GoTo 0
Set qdf = cdb.CreateQueryDef("")
qdf.SQL = "SELECT * INTO [" & tempTableName & "] FROM [tblStockLogin]"
qdf.Parameters("Box").Value = "AR1N"
qdf.Execute
Set qdf = Nothing
Set cdb = Nothing
DoCmd.OutputTo acOutputTable, tempTableName, acFormatXLSX, strXL_Location, True
End Sub
But this causes the error 3265 on the line:
qdf.Parameters("Box").Value = "AR1N"
I have:
Checked that tblStockLogin is spelled correctly
Checked that Box field exist
Remove the parameters line and it works correctly (ie brings ALL data back from the tblStockLogin table)
I am a newbie (both in Access and in using Forums) but I cannot find an answer (that works for me).