I have a report I am trying to filter via code. I seem to be part way there, but the filter is not affecting the report. Here is my code so far:
I have verfied that StrFilter is looping through the rs and being changed each time, but my report always opens with all records. I should only get two pages, instead I get 78. I have tested the filter manually and it does filter that way. I've run out of ideas as to what is wrong, I'm not getting any error messages and I do have the filter on property set to yes in my report.
Thanks, Ken
- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
Code:
Public Function PrintAgntSettleRep()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim StrFilter As String
Set db = CurrentDb
Set rs = db.OpenRecordset("AgentSettlementList")
If Not rs.BOF And Not rs.EOF Then
rs.MoveFirst
End If
Do While Not rs.EOF
StrFilter = "sortcode = """ & rs(0).Value & """"
DoCmd.OpenReport "SettlementReportPage1", acViewPreview, StrFilter
DoCmd.PrintOut acPrintAll, , , acMedium, 1
rs.MoveNext
Loop
rs.Close
Set db = Nothing
End Function
Thanks, Ken
- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg