Frustrating Error when opening a query in VBA code

  • Thread starter Thread starter John Dumay
  • Start date Start date
J

John Dumay

Hi All,

Whenever I want to create a recordset in code using a query that uses a
filter by form variable to refine the data set (or even one that is a
sub-query) i keep getting the following erro when the code tries to create
the recordset.

"Run Time Error '3601' Too Few Parameters Epected 1"

Can someone explain why I get this error and what to do about it? The
frustrating thing is that the query runs perfectly when I design it but not
when I call it in code.

As always any help is really appreciated.

Regards,

john Dumay
 
U¿ytkownik "John Dumay said:
Hi All,

Whenever I want to create a recordset in code using a query that uses a
filter by form variable to refine the data set (or even one that is a
sub-query) i keep getting the following erro when the code tries to create
the recordset.

"Run Time Error '3601' Too Few Parameters Epected 1"

Can someone explain why I get this error and what to do about it? The
frustrating thing is that the query runs perfectly when I design it but
not
when I call it in code.


You have to list the parameters of query. Modify Your code to something like
this:

Dim q As QueryDef, p As Parameter, rs As Recordset
Set q = CurrentDb.QueryDefs("QueryParam")
For Each p In q.Parameters
p.Value = Eval(p.Name)
Next
Set rs = q.OpenRecordset()
'(...) any recordset operations
Set rs = Nothing
Set q = Nothing


K.P. MVP, Poland
www.access.vis.pl
 
Hi Krzysztof,

Man what a relief, that worked perfectly.

many thanks for your assistance!

Regards,

John Dumay
 
Back
Top