OpenRecordset error

G

Guest

Can someone help with this? When I try to open a query as a recordset using
DAO, I get this error after the code runs.

Error:
Error # 3061 was generated by DAO.Database.
Too few parameters. Expected 1. at Line# 200.

Code:
Dim rs As DAO.Recordset
Set rs = CurrentDB.OpenRecordSet("qryValidateDWE", dbOpenDynaset)

Thanks in advance,
 
G

Guest

Does the query - qryValidateDWE expect any parameters?

Run the query and see if you get any message for parameter input
 
D

Dirk Goldgar

Glenn Suggs said:
Can someone help with this? When I try to open a query as a
recordset using DAO, I get this error after the code runs.

Error:
Error # 3061 was generated by DAO.Database.
Too few parameters. Expected 1. at Line# 200.

Code:
Dim rs As DAO.Recordset
Set rs = CurrentDB.OpenRecordSet("qryValidateDWE", dbOpenDynaset)

Thanks in advance,

If your query makes references to controls on forms (e.g,
"[Forms]![FormName]![ControlName]"), those references are considered to
be parameters. When Access runs the query, it knows how to resolve
those parameters and fill in the values. However, when you use DAO to
open a recordset, the database engine is operating at a level below
Access, and it doesn't know how to resolve such parameters -- you have
to do it yourself.

Is this what's going on with your query? If so, you can use the DAO
QueryDef and Parameter objects to resolve the parameters before opening
the recordset. Like this:

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

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

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

Set rs = qdf.OpenRecordset

If that was not your problem, the message still means you have something
in the query that DAO thinks is a parameter. Maybe it's a real
parameter, or maybe it's just a word that is misspelled.
 
G

Guest

Thanks, Dirk. Your solution worked great and yes, it was apparently
parameters in the query, looking for information on a form, that caused the
problem. At first I thought it might have something to do with the table in
the query because it was an Oracle table connected with ODBC and the DAO
procedure seemed to work when I used an Access table. Anyway, it's working
now.

Thanks again
--
Glenn


Dirk Goldgar said:
Glenn Suggs said:
Can someone help with this? When I try to open a query as a
recordset using DAO, I get this error after the code runs.

Error:
Error # 3061 was generated by DAO.Database.
Too few parameters. Expected 1. at Line# 200.

Code:
Dim rs As DAO.Recordset
Set rs = CurrentDB.OpenRecordSet("qryValidateDWE", dbOpenDynaset)

Thanks in advance,

If your query makes references to controls on forms (e.g,
"[Forms]![FormName]![ControlName]"), those references are considered to
be parameters. When Access runs the query, it knows how to resolve
those parameters and fill in the values. However, when you use DAO to
open a recordset, the database engine is operating at a level below
Access, and it doesn't know how to resolve such parameters -- you have
to do it yourself.

Is this what's going on with your query? If so, you can use the DAO
QueryDef and Parameter objects to resolve the parameters before opening
the recordset. Like this:

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

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

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

Set rs = qdf.OpenRecordset

If that was not your problem, the message still means you have something
in the query that DAO thinks is a parameter. Maybe it's a real
parameter, or maybe it's just a word that is misspelled.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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

Similar Threads


Top