Others

How to Use VBA to Find Specific Text in an Access Text Box

Jason MillerJason Miller Oct 28, 2026 869 views

Question details

The user needs to locate a specific text phrase within a large text field on a Microsoft Access form using VBA.

How to Use VBA to Find Specific Text in an Access Text Box
Product
Microsoft Access
Device & OS
not provided
Scenario
Searching for a specific string such as "CASE LINE UP" inside a form's text box programmatically.
Observed behavior
Requires a VBA solution to determine if the phrase exists and to navigate to the matching record if found.
Before you start

Ensure you have a basic understanding of writing VBA code in Microsoft Access, and verify the exact name of the target text box field on your form.

Solution 1Recommended

Use a DAO Recordset Clone and FindFirst Method

Utilize a DAO recordset clone to search the underlying data for the specific text and move the form's bookmark to the matching record.

This method searches the form's underlying recordset without affecting the current view until a match is found. Using the Like operator allows for flexible substring matching.

1
Open the VBA Editor

Press Alt + F11 to open the VBA Editor and locate the module for your specific Access form.

2
Declare the Recordset Variable

Inside your search button's click event, declare a recordset clone variable by typing: Dim rs As DAO.Recordset.

3
Set the Clone to the Form's Recordset

Assign the clone by typing: Set rs = Me.RecordsetClone. This creates a hidden copy of the data currently on the form.

4
Execute the FindFirst Method

Use the FindFirst method with the Like operator to search the field: rs.FindFirst "[YourFieldName] Like '*CASE LINE UP*'" (replace YourFieldName with your actual text box control source).

5
Handle the Result

Add an If statement: If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark Else MsgBox "Phrase not found.". This moves the form to the record if a match is found, or alerts the user if it isn't.

Dynamic Searching: You can replace the hardcoded phrase '*CASE LINE UP*' with a reference to another text box on your form to create a dynamic search tool.
Free Microsoft Office alternative

Looking for a Lightweight and Free Office Suite?

While WPS Office does not currently offer a direct database alternative to Microsoft Access, it provides powerful, free tools for Word, Excel, and PowerPoint files. If you frequently handle data manipulation, searching, and filtering, WPS Spreadsheet is an excellent, lightweight option to process large datasets seamlessly.

Fully compatible with Microsoft Excel (.xlsx, .xls) and CSV formatsBuilt-in advanced search, filter, and data validation featuresLightweight, free to use, and features a familiar user interface
microsoft office alternative - wps office

Frequently Asked Questions

Can I use a variable or another text box for the search phrase in VBA?

Yes. Instead of hardcoding the search phrase, you can concatenate a text box value into the FindFirst string. For example: rs.FindFirst "[MyField] Like '*" & Me.SearchBoxName & "*'".

How do I find exact complete words instead of substrings in Access?

Using the Like operator with asterisks (*) matches any substring. To find exact whole words and avoid unintended partial matches, you will need to implement a custom VBA function that parses the text string or utilizes regular expressions to respect word boundaries.

What happens if the Access text box is empty or null?

If the text box or the underlying field might be null, you should include a check in your VBA code. Using the Nz() function or verifying IsNull(Me.MyField) before executing the search can prevent unexpected runtime errors.