Opening a Recordset

E

Eddy

I am trying to open a recordset of a query that has some Criteria. I am
using the following code:
Set rsTot = db.OpenRecordset("qryTotal", dbOpenDynaset)

The qryTotal has criteria so it opens to a specific record. In the criteria
for a field I have:
=Form1!Field1

When the code attempts to open the record set I get the error "Too Few
Parameters, Expect 1"

My question is how or can I include the parameters in the Set statement
above so the code can open the qryTotal and set the recordset?

Thanks
 
D

Dirk Goldgar

Eddy said:
I am trying to open a recordset of a query that has some Criteria. I
am using the following code:
Set rsTot = db.OpenRecordset("qryTotal", dbOpenDynaset)

The qryTotal has criteria so it opens to a specific record. In the
criteria for a field I have:
=Form1!Field1

When the code attempts to open the record set I get the error "Too Few
Parameters, Expect 1"

My question is how or can I include the parameters in the Set
statement above so the code can open the qryTotal and set the
recordset?

You have to work with the QueryDef object, and fill in the parameters
yourself. Here's a handy trick that relieves you of the need to specify
the parameter(s) by name:

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim rsTot As DAO.Recordset

Set db = CurrentDb
Set qdf = db.QueryDefs("qryTotal")

For Each prm in qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm

Set rsTot = qdf.OpenRecordset

' ... work with rsTot ...

rsTot.Close

Set rsTot = Nothing
Set qdf = Nothing
Set db = Nothing
 

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