logo
search
Others

How to Apply an Access Report Filter When the Report Opens

Olivia MillerOlivia Miller Oct 15, 2026 869 views

Question details

The user needs to prompt for or select a filter condition, such as a Yes/No field, before generating and opening a Microsoft Access report.

Apply an Access Report Filter When the Report Opens
Product
Microsoft Access
Device & OS
not provided
Scenario
Generating a customized database report based on user input, specifically filtering records where a boolean field is set to Yes before the report opens.
Observed behavior
The goal is to apply a dynamic filter conditionally upon opening, rather than opening the report with all records displayed by default.
Before you start

Ensure you have basic familiarity with Access Forms, the Visual Basic for Applications (VBA) editor, and the Design View of your database.

Solution 1Recommended

Use a Form with a Command Button and WhereCondition

Create a user-friendly form with a checkbox that passes a specific filter string to the report using the DoCmd.OpenReport method.

This method is highly recommended as it keeps the user interface clean and separates the filtering logic from the report itself. By using a form, you can easily expand criteria later if needed.

1
Create a selection form

Open your Access database, navigate to the Create tab, and create a new Form. Add a Check Box control to the form and name it 'chkYesNo' in the Property Sheet.

2
Add a command button

Add a Command Button to the same form and name it 'cmdReport'. This button will be used to trigger the report generation.

3
Insert VBA code for the button click event

Right-click the command button, select Build Event, and choose Code Builder. In the VBA editor, add the following logic to the Click event: Dim strWhere As String. Then, add an If statement: If Me.chkYesNo Then strWhere = "[blnMyYesNo] = True".

4
Execute the report opening command

Directly below the If statement, add the command to open the report: DoCmd.OpenReport ReportName:="YourReportName", View:=acViewPreview, WhereCondition:=strWhere. If the checkbox is unchecked, strWhere remains empty and all records are shown.

Use a Form with a Command Button and WhereCondition
Error Handling Tip: It is good practice to add an On Error GoTo ErrHandler statement to gracefully handle situations where the user cancels the report opening process (Error 2501).
Free Microsoft Office alternative

Looking for a Free and Powerful Office Suite?

While Microsoft Access is a specialized tool for database management, you likely need a reliable suite for documents, spreadsheets, and presentations. WPS Office is a lightweight, fully compatible alternative to Microsoft Office that meets all your daily productivity needs for free.

  1. 1. Download WPS Office: Visit the official WPS website to download the free installation package for your operating system.
  2. 2. Install and Launch: Follow the on-screen instructions to install the suite in seconds, then open the unified workspace.
  3. 3. Open Your Files Seamlessly: Drag and drop your existing .docx, .xlsx, or .pptx files directly into WPS Office to continue working with complete formatting preserved.
Fully compatible with Microsoft Word, Excel, and PowerPoint formatsLightweight and runs smoothly on Windows, Mac, Linux, iOS, and AndroidFamiliar user interface for a seamless transitionBuilt-in PDF editing capabilities at no extra cost
microsoft office alternative - wps office

Frequently Asked Questions

Can I filter an Access report without using VBA?

Yes, you can use parameter queries as the data source for your report. By entering a prompt like [Enter Yes or No:] in the criteria row of your query, Access will automatically ask for input before opening the report.

What happens if I leave the WhereCondition blank in DoCmd.OpenReport?

If the WhereCondition parameter is left blank or passed as an empty string, the report will open without any filters applied, displaying all records from its underlying table or query.

How do I filter a report based on a text field instead of a Yes/No field?

To filter based on text, you must wrap the criteria string in single quotes within your VBA code. For example: strWhere = "[Category] = 'Sales'".

Why is my report opening blank after applying a filter?

This usually happens if the criteria provided in the WhereCondition does not match any records in the database, or if the field name referenced in the VBA string is spelled incorrectly.