Frustrating Error when opening a query in VBA code

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
 
K

Krzysztof Pozorek [MVP]

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
 
J

John Dumay

Hi Krzysztof,

Man what a relief, that worked perfectly.

many thanks for your assistance!

Regards,

John Dumay
 
T

Tom van Stiphout

On Mon, 21 Jan 2008 21:53:12 +0100, "Krzysztof Pozorek [MVP]"

Elegant!

-Tom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top