You can filter a Microsoft Access report by a combo box by placing an unbound combo box on a form, then using a command button or the combo box's AfterUpdate event to open the report with a WHERE clause that references the combo box value. This passes only matching records to the report. The technique works in all modern Access versions and is one of the most common ways to add interactive filtering to reports without building multiple report designs.
Why Filter Reports with a Combo Box?
Reports in Access are static by design: they display the records returned by their Record Source. To show a subset—such as orders for one customer, sales for one month, or tasks for one employee—you need to supply a filter at the moment the report opens. A combo box gives users a familiar dropdown list of valid choices, reducing typing errors and making the report feel like a proper application. Unlike parameter prompts, which require the user to type a value exactly, a combo box restricts input to a list, so the filter is more reliable and user-friendly.
This approach also avoids creating a separate report for every possible filter value. One report design can serve many views, which simplifies maintenance. The combo box can be bound to a lookup table or use a value list, and it can be placed on a form dedicated to report launching or on a dashboard form.
How the Filtering Mechanism Works
Access reports accept a WHERE condition when opened with the DoCmd.OpenReport method. The syntax is:
DoCmd.OpenReport "ReportName", acViewPreview, , "CustomerID = " & Me.cboCustomer
The fourth argument is the filter string. It must be a valid SQL WHERE clause without the word WHERE. For text fields, you need to add quotes around the value; for dates, use the American date format (#mm/dd/yyyy#) or a function like Format to avoid locale issues. For numeric fields, no delimiters are needed.
When the report opens, Access applies the filter to the report's Record Source. The report's own Filter property is not changed; the filter is applied only for that instance. If the report is later opened without the filter, it shows all records.
You can trigger the OpenReport call from a button's Click event or from the combo box's AfterUpdate event. Using AfterUpdate gives immediate feedback: the user selects a value and the report opens right away. A button gives more control, letting the user review the selection before opening.
Step-by-Step: Building the Filter
- Create or identify the report. The report should be based on a query or table that includes the field you want to filter by. For example, a report based on the Orders table with a CustomerID field.
- Create a form to host the combo box. An unbound form is fine. This form will stay open while the report is previewed.
- Add an unbound combo box. In Design View, use the Combo Box wizard. Choose the option to look up values from a table/query or type a custom value list. Select the field that matches the report's filter field (e.g., CustomerID). If you want to show a name but filter by ID, include both columns and set the bound column to the ID.
- Name the combo box. Give it a meaningful name like cboCustomer. This name is used in the VBA code.
- Add a command button (optional). If you prefer a button, add one and name it cmdPreview. Otherwise, you will use the combo box's AfterUpdate event.
- Write the VBA code. Open the form's module and add the following code (adjust names and field types):
Private Sub cmdPreview_Click()
Dim strFilter As String
If IsNull(Me.cboCustomer) Then
MsgBox "Please select a customer."
Exit Sub
End If
strFilter = "CustomerID = " & Me.cboCustomer
DoCmd.OpenReport "rptOrders", acViewPreview, , strFilter
End Sub
For a text field, use: strFilter = "CustomerName = '" & Me.cboCustomer & "'". For a date field, use: strFilter = "OrderDate = #" & Format(Me.cboDate, "mm/dd/yyyy") & "#".
- Test the form. Switch to Form View, select a value, and click the button (or change the selection if using AfterUpdate). The report should open showing only matching records.
Handling Different Data Types
The filter string must match the data type of the field in the report's Record Source. Common pitfalls include:
- Text fields: Enclose the value in single quotes. If the value itself contains an apostrophe (e.g., O'Brien), you must escape it by doubling the apostrophe:
Replace(Me.cboName, "'", "''"). - Date fields: Use # delimiters and format as mm/dd/yyyy to avoid ambiguity. Access interprets dates according to the system's regional settings; explicit formatting prevents errors.
- Numeric fields: No delimiters needed. Ensure the combo box's bound column is the numeric ID, not a text description.
- Boolean fields: Use True or False without quotes.
If the combo box has multiple columns and the bound column is not the first, the value returned by Me.cboCustomer is the bound column's value. This is often the primary key, which is what you want for filtering.
Common Problems and Solutions
Even experienced Access developers encounter issues. Here are frequent ones:
- Report shows all records: The filter string may be empty or invalid. Check that the combo box has a value and that the field name in the filter matches the report's Record Source exactly. Use the Immediate window to test the filter string with a Debug.Print.
- Error 3075 (Syntax error in query expression): Usually caused by missing quotes or incorrect date delimiters. Review the filter string construction.
- Combo box shows ID instead of name: Adjust the column widths property to hide the ID column (set width to 0) and set the bound column to the ID.
- Filter works in preview but not when printed: The filter is applied to the report's data, so printing should respect it. If not, ensure you are not using the report's Filter property separately.
- Combo box on the report itself: Reports do not support interactive combo boxes in Print Preview. The combo box must be on a form.
A common misconception is that you can place a combo box directly on a report and have it filter the report's data. Reports are not interactive in Preview or Print view; controls are for display only. The filtering must be done before the report opens, typically via a form.
Alternative Approaches
While the combo box on a form is the most flexible method, other options exist:
- Parameter query: When the report opens, Access prompts for the value. This is simpler but less user-friendly and error-prone.
- Filter by form: Access's Filter by Form feature lets users set criteria in a spreadsheet-like grid, but it is not as controlled as a combo box.
- Navigation form with embedded report: You can embed a report in a navigation form and use a combo box to set the report's Filter property via VBA. This keeps everything on one screen but requires more coding.
- DoCmd.OpenReport with a saved filter: You can save a filter with the report and apply it, but this is less dynamic.
The combo box method strikes a balance between control and simplicity, and it is widely used in Access applications.
Frequently Asked Questions
Can I filter a report by a combo box without VBA?
Yes, you can use a macro. Create a macro with the OpenReport action, and in the Where Condition argument, reference the combo box using an expression like [Forms]![MyForm]![cboCustomer]. This achieves the same result without writing code, though VBA offers more error handling.
Why does my filter return no records?
Check that the value in the combo box matches the data type and format of the field. For text, ensure quotes are included; for dates, use # delimiters. Also verify that the field name in the filter string exactly matches the field in the report's Record Source.
Can I use a multi-select combo box to filter by multiple values?
Standard combo boxes do not support multiple selections. You would need a list box with Multi Select property set to Simple or Extended, then build an IN clause in the filter string. This requires more complex VBA.
How do I filter by a date range using two combo boxes?
Use two combo boxes for start and end dates, then build a filter like "OrderDate Between #" & Format(Me.cboStart, "mm/dd/yyyy") & "# And #" & Format(Me.cboEnd, "mm/dd/yyyy") & "#". Ensure both are filled before opening the report.
Does the filter affect the report's underlying query?
No, the filter is applied only to the report instance. The query itself remains unchanged. If you open the report without the filter, all records appear.
Can I use a combo box on a report to filter itself?
No, reports are not interactive in Preview or Print view. Combo boxes on reports are for display only. Use a form to host the combo box and open the report with a filter.