Too Few Parameters Error

  • Thread starter Thread starter Gideon
  • Start date Start date
G

Gideon

DAO question:

The following is part of a sub that has to be executed
when a command button in FORM1 is clicked:
==========================================
..
..
Set RecSet1 = Dbs.OpenRecordset("Query2",dbOpenSnapshot)
..
..
===================================================
Query2 is predefined outside. It uses an ODBC table, and
has a criterion that uses a textbox in this FORM1.

Upon execution I get an error "Too few parameters".

Removing the criterion from Query2 stops the error, but I
need the criterion.

I do not understand why I get the error, and how to solve
it.
 
DAO question:

The following is part of a sub that has to be executed
when a command button in FORM1 is clicked:
==========================================
.
.
Set RecSet1 = Dbs.OpenRecordset("Query2",dbOpenSnapshot)
.
.
===================================================
Query2 is predefined outside. It uses an ODBC table, and
has a criterion that uses a textbox in this FORM1.

You need to evaluate the parameter before opening the recordset. Try

Dim qd As DAO.Querydef
Dim prm AS DAO.Parameter
Set qd = dbs.Querydefs("Query2")
For Each prm In qd.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set RecSet1 = qd.OpenRecordset
 
Back
Top