How to Prevent Access Search from Running When Exiting a Form
Question details
The user needs to stop an unwanted, incomplete search from executing when clicking an Exit button on a Microsoft Access form.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A user clicks an Exit Search button on a form, which causes the active unbound search control to lose focus.
- Observed behavior
- Losing focus triggers the control's After Update event, running an incomplete artist search before the form can close.
Ensure you have a recent backup of your Microsoft Access database and open your target form in Design View before modifying VBA event procedures.
Move the Search Call to the Key Down Event
Trigger the search only when the user explicitly presses the Enter key, rather than firing whenever the control loses focus.
By default, the After Update event fires as soon as a control loses focus if its contents have changed. Shifting the trigger to the Key Down event allows you to intercept the specific keystrokes (like the Enter key) before other form actions take over.
In Design View, click on your unbound search control. Open the Property Sheet, go to the Event tab, and click the ellipsis (...) next to the 'On Key Down' property.
In the VBA window, add an If statement to check for the Enter key. Use: If KeyCode = vbKeyReturn Then [YourSearchFunction] : KeyCode = 0 : End If.
Navigate to the control's 'After Update' event in the Property Sheet and delete the existing search macro or VBA call to prevent duplicate triggers.
Save your form and switch to Form View. Type a search term and click the Exit button; the search should no longer run unless you press Enter.

Replace Text Boxes with a Combo Box
Use a combo box designed for searching and selecting records to bypass complex text box event handling.
Manage Your Data with WPS Spreadsheet
If you frequently work with data tables, queries, and reports, WPS Office provides a lightweight, highly compatible alternative to the Microsoft Office suite. Enjoy seamless data analysis and management without the steep learning curve of complex database software.
- 1. Download and Install: Visit the official WPS website to download the free WPS Office suite and install it on your device.
- 2. Open WPS Spreadsheet: Launch the application and select Spreadsheet to begin organizing, filtering, and analyzing your data.
- 3. Import Existing Data: Easily open your existing Excel workbooks or CSV exports to continue your data management seamlessly.

Frequently Asked Questions
Why does the After Update event trigger when I click the Exit button?
In Microsoft Access, the After Update event fires as soon as a control loses focus, provided the data inside it has changed. Clicking anywhere else on the form, including an Exit button, forces the control to lose focus.
What is vbKeyReturn in Access VBA?
vbKeyReturn is a built-in VBA constant representing the Enter (or Return) key on the keyboard. It is equivalent to the numeric KeyCode value of 13.
Can I use macros instead of VBA for the Key Down event?
Yes. You can attach a macro to the On Key Down event and use a macro condition like [KeyCode]=13 to verify if the Enter key was pressed before executing your search action.




