Hi,
I am having an issue on 2007 where I am trying to loop through query results and print a report based on a field in the query.
heres my code:
Private Sub Command81_Click()
Dim db As DAO.Database, rs As DAO.Recordset
Dim strReport As String
Set db = CurrentDb()
Set rs = db.Openrecordset("LateReport")
rs.MoveFirst
Do While Not rs.EOF
strReport = "Attendance" & rs.Fields("max")
DoCmd.OpenReport strReport
rs.MoveNext
Loop
End Sub
"LateReport" is the query which is dependant on a date field from a form (not this query in particular, but a query that LateReport uses).
So because of that i am getting the error:
Run time error 3061. Too few parameters: expected 1
on the line:
Set rs = db.Openrecordset("LateReport")
I have tried replacing it with:
Set rs = db.Openrecordset("SELECT * FROM LateReport WHERE Forms!frmmain!caldate.value = #" & Forms!frmmain!caldate.value & "#;")
As well as hard coding in a random date and other variations, to no avail.
Any ideas on how to make this work properly?
Thanks in advance
I am having an issue on 2007 where I am trying to loop through query results and print a report based on a field in the query.
heres my code:
Private Sub Command81_Click()
Dim db As DAO.Database, rs As DAO.Recordset
Dim strReport As String
Set db = CurrentDb()
Set rs = db.Openrecordset("LateReport")
rs.MoveFirst
Do While Not rs.EOF
strReport = "Attendance" & rs.Fields("max")
DoCmd.OpenReport strReport
rs.MoveNext
Loop
End Sub
"LateReport" is the query which is dependant on a date field from a form (not this query in particular, but a query that LateReport uses).
So because of that i am getting the error:
Run time error 3061. Too few parameters: expected 1
on the line:
Set rs = db.Openrecordset("LateReport")
I have tried replacing it with:
Set rs = db.Openrecordset("SELECT * FROM LateReport WHERE Forms!frmmain!caldate.value = #" & Forms!frmmain!caldate.value & "#;")
As well as hard coding in a random date and other variations, to no avail.
Any ideas on how to make this work properly?
Thanks in advance