Hi. I am trying to export a query I stored as a String in VBA (SQLstr) into Excel. However, it gives me the following error:
Could not create spreadsheet.
Error: 3061
Desc: Too few parameters. Expected 2.
The code I am using is as follows (with unimportant stuff left out):
Dim db As Database
Dim rs As Recordset
Dim xl As Object
Dim objWkb, objSht As Variant
Dim SQLstr As String
SQLstr = "SELECT [bunch of stuff] FROM [tablename] WHERE Date Between #1/1/01# AND #1/1/03# ORDER BY Date DESC"
Set db = CurrentDb
Set rs = db.OpenRecordset(SQLstr)
Set xl = CreateObject("Excel.Application")
If rs.RecordCount > 0 Then
With xl
Set objWkb = .Workbooks.Add
Set objSht = objWkb.Worksheets(1)
With objSht
.Cells(2, 1).CopyFromRecordset rs
End With
End With
End If
After inserting some Msgboxes to isolate where the error is occurring, I found that it is happening when I try to do the "Set rs" line of code.
Any help with this would be greatly appreciated.
Thanks,
~Seth Neustein
Could not create spreadsheet.
Error: 3061
Desc: Too few parameters. Expected 2.
The code I am using is as follows (with unimportant stuff left out):
Dim db As Database
Dim rs As Recordset
Dim xl As Object
Dim objWkb, objSht As Variant
Dim SQLstr As String
SQLstr = "SELECT [bunch of stuff] FROM [tablename] WHERE Date Between #1/1/01# AND #1/1/03# ORDER BY Date DESC"
Set db = CurrentDb
Set rs = db.OpenRecordset(SQLstr)
Set xl = CreateObject("Excel.Application")
If rs.RecordCount > 0 Then
With xl
Set objWkb = .Workbooks.Add
Set objSht = objWkb.Worksheets(1)
With objSht
.Cells(2, 1).CopyFromRecordset rs
End With
End With
End If
After inserting some Msgboxes to isolate where the error is occurring, I found that it is happening when I try to do the "Set rs" line of code.
Any help with this would be greatly appreciated.

Thanks,
~Seth Neustein