Office Apps Crashing

How to Fix Microsoft Access Crashes When Using InStr Function

Adam DavisAdam Davis Nov 3, 2026 868 views

Question details

Microsoft Access crashes or stops responding when executing an InStr expression in the AfterUpdate event of a form.

How to Fix Microsoft Access Crashes When Using InStr Function
Product
Microsoft Access
Device & OS
not provided
Scenario
Running VBA code in a form's AfterUpdate event to search for specific string values to enable or disable controls.
Observed behavior
The application stops responding completely. The issue persists even after compacting, repairing, debugging, or recreating the Access database.
Before you start

Before modifying your VBA code, open the VBA Editor and compile your database to rule out any glaring syntax errors, and temporarily disable the AfterUpdate event to confirm it is the source of the crash.

Solution 1Recommended

Replace the InStr Function with a Custom Split Function

Create a custom function in a general module using the Split method to bypass the instability caused by InStr in the AfterUpdate event.

In certain specific form event scenarios, the built-in InStr function can cause an unhandled loop or memory issue, causing Access to freeze. Utilizing a custom search function based on the Split command accomplishes the same goal more reliably.

1
Open the VBA Editor

Press Alt + F11 while in Microsoft Access to open the Visual Basic for Applications (VBA) editor.

2
Insert a General Module

Click on 'Insert' in the top menu and select 'Module' to create a new general module outside of your specific form's code.

3
Create the Occurs Function

Write a custom function (e.g., named Occurs) that uses the VBA Split function to search for the required string values and returns the count.

4
Update the Form Event

Navigate back to your form's AfterUpdate event code. Replace the existing InStr calls with calls to your new Occurs function.

5
Test the Output

Configure the event to check if the Occurs function returns a value greater than zero, and use that result to enable or disable the required controls (e.g., SCAP_Countries or SIAP_Type).

Replace the InStr Function with a Custom Split Function
Optimize Code: While replacing the function, review the surrounding code. Simplifying redundant code blocks can further improve the stability and performance of your form.
Free Microsoft Office alternative

Manage Data Smoothly with WPS Office

While WPS Office does not feature a direct database application like Microsoft Access, you can easily handle extensive data sets, lists, and form logic using WPS Spreadsheet. Avoid complex VBA crashes and easily organize your data in a highly compatible environment.

Free and lightweight Office suite with rich data management toolsHigh compatibility with Microsoft Excel formats (.xlsx, .xls, .csv)Built-in advanced formulas without the need for complex VBA programmingFamiliar user interface for seamless migration
QA img-9

Frequently Asked Questions

Why does the InStr function cause Microsoft Access to crash?

While InStr is a standard VBA function, combining it with specific data-bound form events like AfterUpdate can sometimes trigger an unhandled loop or conflict with the form's control states, causing the application to hang or crash.

Will compacting and repairing the database fix VBA crashes?

Compacting and repairing is excellent for fixing general database corruption and bloat. However, it rarely resolves code-level bugs or specific function incompatibilities like the InStr crash within an AfterUpdate event.

How do I identify redundant VBA code in my Access project?

Open the VBA Editor and manually review your event handlers to ensure you aren't running duplicate checks, repeating the same string searches, or running unnecessary nested loops. Consolidating repeated actions into a single general-module function helps reduce redundancy.