VBA & Macro Problems

How to Fix Access Query Repeatedly Calling VBA Function Loop

Khadija KhanKhadija Khan Oct 29, 2026 868 views

Question details

A Microsoft Access query running a VBA function gets stuck in an infinite loop and never finishes execution.

How to Fix Access Query Repeatedly Calling VBA Function Loop
Product
Microsoft Access
Device & OS
not provided
Scenario
Running a query that executes a VBA function for every row in a table while attempting to debug or display message boxes.
Observed behavior
The query continuously triggers the VBA function in an endless loop, typically occurring when switching between the Access window and the VBA editor while execution is paused.
Before you start

Ensure you save your current database progress and make a note of the exact VBA function being called in your Access query to prevent data loss if a forced restart is required.

Solution 1Recommended

Stop Debugging and Restart the Process

Resolve the infinite loop caused by switching between the VBA Editor and Access window during breakpoints.

When a query calls a VBA function and hits a breakpoint or message box, switching focus back to the Access window forces the query to refresh. This triggers the VBA function to evaluate again for all rows, creating an endless loop.

1
Clear Message Boxes

Click 'OK' or close any open VBA message boxes currently displayed on your screen.

2
Reset Code Execution

In the VBA Editor, click the 'Reset' button (the square Stop icon in the top toolbar) to completely halt the code execution.

3
Force Restart if Frozen

If the application is entirely unresponsive, press Ctrl + Shift + Esc to open Task Manager, locate Microsoft Access, and select 'End Task' to force close it.

4
Remove Interruptions

Delete any MsgBox functions and remove all breakpoint toggles (F9) in your VBA code before attempting to run the query again.

Stop Debugging and Restart the Process
Preventing the Loop: Avoid switching focus between the Access window and the VBA Editor while code execution is paused to prevent the query from automatically refreshing.
Free Microsoft Office alternative

Looking for a Lightweight Microsoft Office Alternative?

While WPS Office does not feature a direct database equivalent to Microsoft Access, it offers a robust, free alternative for Word, Excel, and PowerPoint tasks. If you are experiencing general MS Office performance issues or need a reliable suite for document management, WPS Office provides excellent compatibility and familiar interfaces.

  1. 1. Download the Installer: Visit the official WPS Office website and click the 'Download' button.
  2. 2. Install the Suite: Run the downloaded installer and follow the on-screen prompts to complete the setup.
  3. 3. Start Creating: Open WPS Office to instantly create, edit, and save your documents, spreadsheets, and presentations.
Free, lightweight, and fast-loading office suite.Seamless compatibility with Microsoft Office formats like DOCX, XLSX, and PPTX.Built-in PDF editing tools for streamlined document management.Familiar user interface requiring zero learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why does switching windows in MS Access trigger the VBA function again?

Switching focus back to the Access window while a macro is paused forces the active query to refresh its display. Since the query relies on the VBA function to calculate values for its rows, the refresh triggers the function to run again, creating an infinite loop.

How can I debug a VBA function called from an Access query safely?

Instead of using breakpoints or MsgBox pop-ups inside a function called by a query, use Debug.Print to output variable values to the Immediate Window. This allows you to monitor the function's behavior without pausing code execution and triggering a loop.

Can I stop an Access query that is stuck in a continuous loop without restarting?

You can try pressing Ctrl + Break (or Pause/Break) on your keyboard to manually interrupt the execution. If the VBA Editor captures the interruption, you can halt the code. If the application is completely frozen, restarting via Task Manager is the only solution.