Too Few Parameters: Expected 1

  • Thread starter Thread starter jb
  • Start date Start date
J

jb

I have a select query in my A2K database called qryTest. If I double-click
on
this, it brings up a recordset of records based on the criteria of the
query. However, in code, if I do a

Set rstMySet = dbcurrent.OpenRecordSet("qryTest")

I get an error "too few parameters: Expected 1" (dbcurrent & rstMySet
already defined). This query is based on an ODBC link to a third party
database.

So, I created a strSql string variable, copied the contents of
the query into that variable and touched up the quotes, etc., and then tried
the openrecordset(strSql) and
that gave me the same message.

If I go and make a simple query that returns records out of an Access
table (qryTest2) and not through ODBC, the openrecordset(qryTest2) works
fine. Is it because of
ODBC or is their something missing? I've tried adding some constants too
after the qryTest like dbopenforwardonly or dbopensnapshot, etc, but no luck
there either. Again, if I click on the query from the database window, it
opens fine and selects the correct group of records.

Thanks for any help.

John
 
JB:

If qryTest is a parameter query, try defining that parameter before
executing the query. I'm still on Access 97, and this is how it would be
done. Don't know if you'll have to change it for Access 2K or not...

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim sQryName As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("qryTest")
' *** set the parameter here. ***
' ***Change the "Forms!frmName!txtFieldName" to your parameter***
qdf.Parameters(0) = Forms!frmName!txtFieldName
Set rs = qdf.OpenRecordset

rs.MoveFirst

'Processing done here

qdf.Close
rs.Close
Set rs = Nothing

HTH!
 
Back
Top