Search code examples
vbams-access

How to show in the report only the rows that I see when I apply a filter?


In Access (Access 2021), I have a form in which I have some rows. The filter button, I filter some rows to see only some of them.

In this form, I have a button that opens a report and print the rows. The problem is that in the report I see all the rows of the table, not only the rows that I am seeing in the form.

How could I tell the report to print only the rows that I am seeing?

Thanks.


Solution

  • Options:

    1. report RecordSource is parameterized query that references controls on form used to select filter criteria

    2. VBA procedure builds a filter string from controls on form used to select filter criteria and apply when opening report

    3. apply same filter criteria to report when opening by simply referencing form Filter property: DoCmd.OpenReport "reportname",,, Me.Filter