DAO error

  • Thread starter Thread starter Peter Marshall
  • Start date Start date
P

Peter Marshall

I have used similar VBA code below without problems, but now I am getting a "Run-time error 3061: Too few parameters. Expected 2." Debug stops on the "Set rst = " statement. Can anyone help me with this?

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryTimesInOutCheck", dbOpenSnapshot)

If rst.RecordCount = 0 Then
vbResponse = MsgBox("Record not found", vbOKOnly)
Else
vbResponse = MsgBox("Record found", vbOKOnly)
End If

rst.Close
Set rst = Nothing
Set db = Nothing

End If
 
Obviously your query is expecting two parameters (could be references to
form controls, or to parameter boxes, or whatever). So you need to evaluate
the parameters for the recordset before you open it.


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

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

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

Set rst = qdf.OpenRecordset(dbOpenSnapshot)

If rst.RecordCount = 0 Then
vbResponse = MsgBox("Record not found", vbOKOnly)
Else
vbResponse = MsgBox("Record found", vbOKOnly)
End If

rst.Close
Set rst = Nothing
Set qdf = Nothing
Set db = Nothing

End If

--

Ken Snell
<MS ACCESS MVP>



I have used similar VBA code below without problems, but now I am getting a
"Run-time error 3061: Too few parameters. Expected 2." Debug stops on the
"Set rst = " statement. Can anyone help me with this?

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryTimesInOutCheck", dbOpenSnapshot)

If rst.RecordCount = 0 Then
vbResponse = MsgBox("Record not found", vbOKOnly)
Else
vbResponse = MsgBox("Record found", vbOKOnly)
End If

rst.Close
Set rst = Nothing
Set db = Nothing

End If
 
Double click on the query qryTimesInOutCheck to see what
parameters it asks you for.

(david)

I have used similar VBA code below without problems, but now I am getting a
"Run-time error 3061: Too few parameters. Expected 2." Debug stops on the
"Set rst = " statement. Can anyone help me with this?

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("qryTimesInOutCheck", dbOpenSnapshot)

If rst.RecordCount = 0 Then
vbResponse = MsgBox("Record not found", vbOKOnly)
Else
vbResponse = MsgBox("Record found", vbOKOnly)
End If

rst.Close
Set rst = Nothing
Set db = Nothing

End If
 
Back
Top