Create an Access VBA Search Box to Filter a Datasheet
Question details
The user wants to implement an unbound search control or combo box using VBA to dynamically filter records in an Access split-form datasheet.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Navigating a split-form datasheet containing thousands of customer codes where manual scrolling is highly inefficient.
- Observed behavior
- The user seeks an automated VBA solution to filter the datasheet instantly based on the inputted customer code instead of using the built-in column filters.
Verify the exact data type of the field you intend to filter (text vs. numeric), as this will dictate how the VBA filter expression is formatted.
Use an Unbound Combo Box with an AfterUpdate VBA Event
Implement an unbound combo box to capture the search term and apply a VBA filter string to the form based on the selected value.
A combo box is ideal for this task because it automatically jumps to the first matching value as the user types. Once a selection is made, the AfterUpdate event triggers the filter.
Open your Access split form in Design View. Add a combo box to the form header, ensure its control source is left blank (unbound), and name it cboFindContact.
Select the newly created combo box. Open the Property Sheet, navigate to the Event tab, and click the ellipsis (...) next to 'On After Update' to launch the VBA editor.
Declare a string variable for your filter. If your target field is numeric (e.g., CustomerID), use the following syntax: strFilter = "CustomerID = " & Me.cboFindContact.Value.
If you are filtering a text field rather than a numeric field, wrap the criteria in single or double quotes: strFilter = "LastName = '" & Me.cboFindContact.Value & "'".
Apply the filter string to the form and activate it by adding these two lines: Me.Filter = strFilter followed by Me.FilterOn = True.

Utilize Built-in Datasheet Column Filters
For scenarios where you do not want to write VBA code, you can use the native filtering tools available in the split form's datasheet view.
Manage and Filter Large Datasets Effectively with WPS Office
While WPS Office does not include a direct Microsoft Access database alternative, WPS Spreadsheet offers robust VBA and macro support. It allows you to build custom search boxes, automate data filtering, and manage large datasets securely without the high costs of premium subscriptions.
- 1. Download WPS Office: Visit the official WPS Office website and download the free, lightweight installation package.
- 2. Open your dataset: Launch WPS Spreadsheet and seamlessly open your existing .xlsx or .csv dataset files.
- 3. Enable the Developer Tab: Navigate to the Developer tab to access the built-in VBA editor and create advanced custom filters.

Frequently Asked Questions
Why do I get a data type mismatch error when running my VBA filter?
This error occurs when you apply a text filter to a numeric field or vice versa. Ensure you wrap text values in quotation marks (e.g., "FieldName = '" & Value & "'") and leave numeric values unquoted (e.g., "FieldName = " & Value).
Can I use a text box instead of a combo box to search as I type?
Yes, you can use a text box by placing your VBA code in the OnChange event. However, you must use the .Text property (e.g., Me.txtSearch.Text) instead of .Value to capture keystrokes in real-time. This method often requires extra coding to manage the cursor position as the user types.
Does applying a VBA filter to a split form update both views?
Yes. When you set Me.FilterOn = True on a split form, Microsoft Access automatically synchronizes the filter across both the single form view and the datasheet view simultaneously.
How do I clear the form filter using a button?
You can add a command button to your form and insert VBA code in its OnClick event. Simply set Me.FilterOn = False and clear the value of your search box (e.g., Me.cboFindContact.Value = Null) to reset the datasheet.




