Too few parameters

S

Scott

I have a parameter query which uses a field on an open form as a parameter
to limit the records in said query. My problem is that when I try to use the
query as a datasource in creating a record set, I get an error 'Too few
parameters, expected = 1".

Why can I run the query normally, but not when setting a recordset?

Any help would be appreciated.
Scott
 
B

Brendan Reynolds \(MVP\)

When opening a recordset based on a parameter query, you must set the
parameter in code before opening the recordset. For example ...

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset

Set db = CurrentDb
Set qdf = db.QueryDefs("NameOfYourQueryHere")
qdf.Parameters(0) = Forms!NameOfForm!NameOfTextBox
Set rst = qdf.OpenRecordset()
 
D

Douglas J. Steele

As long as the form is open, it should work. You sure you haven't miskeyed
something?

You might try posting the code you're using.
 
S

Scott

The code behind the button on the form is:

Dim rcsData As Recordset
Dim dbs As Database

Set dbs = CurrentDb
Set rcsData = dbs.OpenRecordset("qry_confirm_registration",
dbOpenDynaset)

rcsData.MoveFirst
etc. etc.

Also, here is a cut and paste of the SQL in the query referred to above. (It
opens fine with the correct record when the form in the where clause is
open.)

SELECT qry_confirm_registration_base.mash_printed,
qry_confirm_registration_base.mash_ID
FROM qry_confirm_registration_base
WHERE
(((qry_confirm_registration_base.mash_ID)=[forms]![frm_master_header]![mash_
ID]));

P.S. All I am doing is popping up a 'print confirm' form on close of a
previewed report, so that I can tick
the 'mash_printed' boolean field for that record and display it on the main
form. (So that the user knows that the record has already been printed)

Thanks again
Scott
 
D

Douglas J. Steele

Did you try Brendan's suggestion?

--
Doug Steele, Microsoft Access MVP



Scott said:
The code behind the button on the form is:

Dim rcsData As Recordset
Dim dbs As Database

Set dbs = CurrentDb
Set rcsData = dbs.OpenRecordset("qry_confirm_registration",
dbOpenDynaset)

rcsData.MoveFirst
etc. etc.

Also, here is a cut and paste of the SQL in the query referred to above. (It
opens fine with the correct record when the form in the where clause is
open.)

SELECT qry_confirm_registration_base.mash_printed,
qry_confirm_registration_base.mash_ID
FROM qry_confirm_registration_base
WHERE
(((qry_confirm_registration_base.mash_ID)=[forms]![frm_master_header]![mash_
ID]));

P.S. All I am doing is popping up a 'print confirm' form on close of a
previewed report, so that I can tick
the 'mash_printed' boolean field for that record and display it on the main
form. (So that the user knows that the record has already been printed)

Thanks again
Scott

Douglas J. Steele said:
As long as the form is open, it should work. You sure you haven't miskeyed
something?

You might try posting the code you're using.

--
Doug Steele, Microsoft Access MVP



use
the
 

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