Too few parameters. 2 required.

djones

New member
Local time
Today, 04:06
Joined
Nov 15, 2006
Messages
6
Hi,

Can anyone help me with the following problem: I get the above error message when I try to open a recordset. If I run the query directly it returns a record with no error messages but when I insert it into my code I get the error. Here's the part of my code that seems to give me the problem, can anyone throw any light on what I'm doing wrong?

Set db = CurrentDb()

strQuery = "SELECT Workfile.Period, Workfile.Year FROM Workfile " & _
"GROUP BY Workfile.Period, Workfile.Year " & _
"HAVING Workfile.Period =[Forms]![Main Form]![CmbPeriod] " & _
"AND Workfile.Year=[Forms]![Main Form]![CmbYear];"

Set rst = db.OpenRecordset(strQuery)

Many thanks, in anticipation....
 
in code it should look like

strQuery = "SELECT Workfile.Period, Workfile.Year FROM Workfile " & _
"GROUP BY Workfile.Period, Workfile.Year " & _
"HAVING Workfile.Period = " & [Forms]![Main Form]![CmbPeriod] & _
"AND Workfile.Year = " & [Forms]![Main Form]![CmbYear]

it might be "where" instead of "having", but i'm not sure
 
also if Workfile is a query needing a criteria met it could cause this error

peter
 
Are the fields Period and Year strings or dates? If the former, you need to put the criteria in single quotations, if the latter you need to use hash (or pound) signs.

e.g.
strQuery = "SELECT Workfile.Period, Workfile.Year FROM Workfile " & _
"GROUP BY Workfile.Period, Workfile.Year " & _
"HAVING Workfile.Period = '" & [Forms]![Main Form]![CmbPeriod] & _
"' AND Workfile.Year = '" & [Forms]![Main Form]![CmbYear] & "';"

or

strQuery = "SELECT Workfile.Period, Workfile.Year FROM Workfile " & _
"GROUP BY Workfile.Period, Workfile.Year " & _
"HAVING Workfile.Period = #" & [Forms]![Main Form]![CmbPeriod] & _
"# AND Workfile.Year = #" & [Forms]![Main Form]![CmbYear] & "#;"
 

Users who are viewing this thread

Back
Top Bottom