K
KHogwood-Thompson
Hi,
I have the following code in a function, when I run it I get an error
message saying that:
The select statement includes a reserved word or argument name that is
mispelled or missing, or the punctuation is incorrect.
My code is as follows:
Private Function cmdExport()
Dim dbD As DAO.Database
Dim rsJOBREF As DAO.Recordset
Dim strFilespec As String
Dim strJOBREF As String
Dim strSheet As String
Dim strSQL As String
Const SQL1 = "SELECT * INTO [Excel 8.0;HDR=Yes;Database="
Const SQL2 = "FROM CVR WHERE JOBNO ="
Set dbD = CurrentDb()
Set rsJOBREF = dbD.OpenRecordset("SELECT JOBNO FROM CVR" _
, dbOpenSnapshot)
strFilespec = "C:\Folder\File.xls"
Do Until rsJOBREF.EOF
'Get JOBREF
strJOBREF = rsJOBREF.Fields("JOBNO").Value
strSheet = CStr(strJOBREF)
'Assemble the SQL query to export one jobref
strSQL = SQL1 & strFilespec & ";].[" & strSheet _
& SQL2 & strJOBREF & ";"
'export it
dbD.Execute strSQL, dbFailOnError
rsJOBREF.MoveNext
Loop
rsJOBREF.Close
End Function
Can anyone see the problem here??
The function creates a recordset that will be used to export the data to
Excel under different tabs.
I have the following code in a function, when I run it I get an error
message saying that:
The select statement includes a reserved word or argument name that is
mispelled or missing, or the punctuation is incorrect.
My code is as follows:
Private Function cmdExport()
Dim dbD As DAO.Database
Dim rsJOBREF As DAO.Recordset
Dim strFilespec As String
Dim strJOBREF As String
Dim strSheet As String
Dim strSQL As String
Const SQL1 = "SELECT * INTO [Excel 8.0;HDR=Yes;Database="
Const SQL2 = "FROM CVR WHERE JOBNO ="
Set dbD = CurrentDb()
Set rsJOBREF = dbD.OpenRecordset("SELECT JOBNO FROM CVR" _
, dbOpenSnapshot)
strFilespec = "C:\Folder\File.xls"
Do Until rsJOBREF.EOF
'Get JOBREF
strJOBREF = rsJOBREF.Fields("JOBNO").Value
strSheet = CStr(strJOBREF)
'Assemble the SQL query to export one jobref
strSQL = SQL1 & strFilespec & ";].[" & strSheet _
& SQL2 & strJOBREF & ";"
'export it
dbD.Execute strSQL, dbFailOnError
rsJOBREF.MoveNext
Loop
rsJOBREF.Close
End Function
Can anyone see the problem here??
The function creates a recordset that will be used to export the data to
Excel under different tabs.