VBA & Macro Problems

Create an Access VBA Search Box to Filter a Datasheet

Amos GikundaAmos Gikunda Nov 2, 2026 869 views

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.

Create an Access VBA Search Box to Filter a Datasheet as You Type
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.
Before you start

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.

Solution 1Recommended

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.

1
Insert an unbound combo box

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.

2
Access the AfterUpdate event

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.

3
Write the filter VBA code

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.

4
Apply text field formatting (If applicable)

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 & "'".

5
Execute the form filter

Apply the filter string to the form and activate it by adding these two lines: Me.Filter = strFilter followed by Me.FilterOn = True.

Use an Unbound Combo Box with an AfterUpdate VBA Event
Handling Empty Search Boxes: To ensure the datasheet displays all records when the combo box is cleared, add an If statement checking for Null values: If IsNull(Me.cboFindContact.Value) Then Me.FilterOn = False.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS Office website and download the free, lightweight installation package.
  2. 2. Open your dataset: Launch WPS Spreadsheet and seamlessly open your existing .xlsx or .csv dataset files.
  3. 3. Enable the Developer Tab: Navigate to the Developer tab to access the built-in VBA editor and create advanced custom filters.
Fully compatible with Microsoft Excel (.xlsx, .xlsm) macro-enabled formatsBuilt-in VBA editor for creating automated search filters and custom controlsIncredibly lightweight installation with an intuitive, familiar user interfaceFree to use for everyday data management and complex spreadsheet tasks
QA img-9

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.