Share via

Parameter Query to recordset

Anonymous
2014-11-05T01:02:46+00:00

I'm having trouble getting a query into a recordset.  the query in question is based on several other queries, and there are half a dozen parameters that come from a form.  The form is open when I run this code and the parameter values are available to the query.  If I just manually open the query it opens just fine, but I can't figure out how to open it into a recordset with code.  When I run the code below I keep getting error code 3061 "Too few parameters.  Expected 0." 

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("QueryName")

Is there something special I have to account for in the code when opening queries with parameters?

Thanks.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-11-05T01:22:52+00:00

You'll need to explicitly populate the parameters. Try

Dim rs As DAO.Recordset

Dim qd As DAO.Querydef

Dim prm As Parameter

Set qd = CurrentDb.QueryDefs("QueryName")

For Each prm In qd.Parameters

   prm.Value = Eval(prm.Name)

Next prm

Set rs = qd.OpenRecordset(dbOpenDynaset)

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful