DAO error

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
 
K

Ken Snell [MVP]

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
 
D

david epsom dot com dot au

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Custom ID Field 4
Table Append gets error 3420 4
Re-using a recordset 6
Do/Loop Dilemma 6
Error '3061' 2
Code error in excel export 0
Using Findfirst recordset to search memo field type 11
What am I missing?! 2

Top