Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA loop thru a query

Status
Not open for further replies.

mikeba1

Programmer
Jan 2, 2005
235
GB
I ger error 3061
Too few parameters, expected 5

Can anyone point me in the correct direction
I use similar code on tables and it works.

Thanks



Dim db As Database
Dim rst As Recordset
Dim strsql As String
strsql = " SELECT qryacctsinterface1.* FROM qryacctsinterface1; "

Set db = CurrentDb()
Set rst = db.OpenRecordset(strsql, dbOpenDynaset)
With rst
If .RecordCount > 0 Then
' some records
' movelast to get no of records
.MoveLast
' records found
MsgBox (rst.RecordCount)
.MoveFirst
' loop thru and do something
Do Until .EOF
' do something

.MoveNext
Loop
End If
.Close
End With
 
I expect there are references to form controls in the criteria of qryacctsinterface1. You would need to declare or resolve these in order to open the recordset. I typically just build a sql statement rather than use a saved query.

Duane
Hook'D on Access
MS Access MVP
 
I'd try something like this:
Code:
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryacctsinterface1")
For Each prm In qdf.Parameters
  prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset
With rst
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top