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)