Error 3061 Too few parameters.

landar

Registered User.
Local time
Today, 04:54
Joined
Feb 6, 2003
Messages
14
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
 
>SQLstr = "SELECT [bunch of stuff] FROM [tablename] WHERE Date Between #1/1/01# AND #1/1/03# ORDER BY Date DESC" <

If you're actually using Date as a column name, you'll encounters problems.
Date is a reserved word in Access.
Change the column name.

As for the error, search the forum, you'll find a number of hits, for instance:

http://www.access-programmers.co.uk...45940&highlight=Error+3061+Too+few+parameters

RV
 
Last edited:
Unfortunately, I had already looked at the previous postings on the error and they were not helpful.

Thank you for pointing out that I was using Date, I had overlooked that. The name has now been changed to ReportDate (alas, this was not the source of my problems, but would have likely been a source of future problems).

What is strange is that this exact same code works fine with another button on the same form. The only differences are with the query stored in SQLstr, which filters by a number instead of a date. Also, the query on the one giving me the problem is HUGE, it contains over 180 fields, and so had to be concatenated with several strings to make the code legible (e.g. SQLstr = "blah"; SQLstr = SQLstr & "blah continued").
 

Users who are viewing this thread

Back
Top Bottom