Saturday, October 23, 2004

Filter a report using a form's filter

There is a relatively simple way of filtering a report by using the filter property of a form. This allows the user to filter any field on the form and then print the displayed records in a report. Now, instead of creating complex queries or multiple controls on a criteria form, you can let the users decide how to filter the report.


This form is based on the customers table from the Northwind sample database. The country field has been filtered to show only those customers located in Germany.

Now, place the following code behind the Preview Report button's On Click event:
DoCmd.OpenReport "rptCustomers", acPreview, , IIf(Me.FilterOn = True, Me.Filter, "")

Now, once the user clicks on the the Preview Report button, the report uses the filter property of the form, if a filter has been set.


Posted by Hello
This report is now filtered using the same filter used on the form.

No comments: