OpenRecordset error

  • Thread starter Thread starter Guest
  • Start date Start date
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,
 
Does the query - qryValidateDWE expect any parameters?

Run the query and see if you get any message for parameter input
 
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.
 
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)
 
Back
Top