Print Only Records Matching a Form’s Filter

Problem

You have a form that you use to view and edit your collection of record and CD albums. On the form, you’ve placed a command button that you use to print the records contained in the form’s recordset. This works fine, but you’d like to enhance the functionality of the form so that when you filter records on the form and then print the report, only the filtered records will print. Is there any way to do this in Access?

Solution

Access includes properties (Filter and FilterOn) of forms and reports that you can use to manipulate form and report filters programmatically. This solution shows you how to use these properties to print on a report only those records filtered by a form.

Load 03-13.MDB and open the frmAlbums form. When you press the Print Records button, you should see the preview of a report, rptAlbums, that includes all 65 records from qryAlbums. Close the report and go back to frmAlbums, which should still be open. Now create a filter of the form’s records using one of the Filter toolbar buttons or the Records Filter command. For example, you might create a filter by using the new Filter By Form facility (see Figure 3-30).

Filter By Form is used to filter records on frmAlbums

Figure 3-30. Filter By Form is used to filter records on frmAlbums

When you finish creating the filter, apply it. You should see a filtered subset of the records (Figure 3-31).

Figure 3-31. The records ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.