Confusing Error Message - Please decypher

N

NelsonP

I'm trying to do the simplest of tasks here -- to set up a recordset based on
a Querydef:

Dim rs As Recordset
Dim qdfTemp As QueryDef

Set qdfTemp = CurrentDb.QueryDefs("Query1")
Set rs = qdfTemp.OpenRecordset(dbOpenSnapshot)

Query1 is a query defined in the Access environment, and the first statement
seems to work properly. The second does not. The compiler provides the
error, "Too few parameters. Expected 2.", regardless of how many parameters
I provide.

If someone could give me a little help with this debug, I'd really
appreciate it. The standard MShelp has proved worthless regarding this issue.
 
J

Jeff Boyce

If you've told Access to use "Query1" as the source for a recordset in code,
and Access tells you it needs two parameters, where are the
parameter-setting statements in the code?

Does "Query1" require two paramaters to run?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
K

Ken Sheridan

You need to evaluate the parameters:

Dim rs As DAO.Recordset
Dim prm AS DAO.Parameter
Dim qdfTemp As DAO.QueryDef

Set qdfTemp = CurrentDb.QueryDefs("Query1")
For Each prm in qdfTemp.Parameters
prm = Eval(prm.Name)
Next prm
Set rs = qdfTemp.OpenRecordset(dbOpenSnapshot)

The parameters must be capable of being evaluated, e.g. references to
controls on an open form, not simple system generated parameter prompts.

Ken Sheridan
Stafford, England
 
N

NelsonP

Ahhh, many thanks to you both. I was mistakenly thinking that access was
looking for parameters for OpenRecordset, not for the query itself.

I really appreciate the help.

Cheers.
 

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