Print report using forms filter

  • Thread starter Thread starter Alan Fisher
  • Start date Start date
A

Alan Fisher

I have a continuous form and would like users to filter by
selection and then print a report which reflects the
records the user has selected. I tried placing Me.Filter
in the Filter Name option for the print command but that
didn't work. Can't use a where statement cause I never
know which field has been filtered. Any help? Thanks.
 
You can apply the Filter of the form as the WhereCondition for your
OpenReport, like this:

Private Sub cmdPreview_Click()
Dim strWhere As String
If Me.FilterOn Then
strWhere = Me.Filter
End If
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
End Sub

If the Filter string contains any reference to some of the non-bound column
of combo boxes, you will need to ensure that the RecordSource for your
report contains those tables as well, and that the tables are aliased so
they match the name Access is using in the filter string. If you are not
sure about that, open the Immeiate Window (Ctrl+G), and enter:
? Forms("Form1").Filter
to see what the filter actually contains.
 
Worked like a champ. Thanks a lot!!!


-----Original Message-----
You can apply the Filter of the form as the WhereCondition for your
OpenReport, like this:

Private Sub cmdPreview_Click()
Dim strWhere As String
If Me.FilterOn Then
strWhere = Me.Filter
End If
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
End Sub

If the Filter string contains any reference to some of the non-bound column
of combo boxes, you will need to ensure that the RecordSource for your
report contains those tables as well, and that the tables are aliased so
they match the name Access is using in the filter string. If you are not
sure about that, open the Immeiate Window (Ctrl+G), and enter:
? Forms("Form1").Filter
to see what the filter actually contains.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.




.
 
Back
Top