logo
search
Office Apps Freezing

How to Fix Microsoft Access Freezing When Opening a Temporary Query

Kushani NimanthikaKushani Nimanthika Oct 1, 2026 868 views

Question details

The user's VBA process in Microsoft Access is freezing indefinitely on the OpenRecordset line after creating a temporary query, despite working perfectly for years.

How to Fix Microsoft Access Freezing When Opening a Temporary Query
Product
Microsoft Access
Device & OS
not provided
Scenario
Running a VBA script that utilizes CreateQueryDef to generate a temporary query and subsequently attempts to open a recordset based on a second SQL statement.
Observed behavior
The Access application completely freezes on the OpenRecordset line, failing to produce results or return an error message.
Before you start

Before debugging your VBA code or altering underlying data, ensure you make a complete copy of your Access database (.accdb or .mdb) to prevent accidental data loss during the troubleshooting process.

Solution 1Recommended

Debug the Generated SQL String Manually

Isolate the issue by extracting the exact SQL code generated by VBA and running it independently in Access to identify syntax or execution errors.

Often, VBA code freezes because the underlying SQL string contains subtle errors or unexpected variables that cannot be processed by the database engine. By printing the SQL to the Immediate window, you bypass the VBA execution loop and can test the query directly.

1
Print to Immediate Window

In your VBA code, insert the line 'Debug.Print strSQL' (or the name of your SQL string variable) just before the 'OpenRecordset' line.

2
Run and Copy SQL

Run your VBA process until it hits a breakpoint or finishes printing. Press Ctrl+G to open the Immediate Window, highlight the printed SQL string, and copy it.

3
Test in a New Query

Go to the Access main window, click 'Create', select 'Query Design', close the 'Show Table' dialog, switch to 'SQL View', paste the copied SQL string, and click 'Run'.

Debug the Generated SQL String Manually
Keep the Temporary Query Alive: Ensure that your VBA script does not automatically delete the temporary query when it freezes. You must confirm the temporary query still exists in the Navigation Pane when you test the SQL manually.
Free Microsoft Office alternative

Switch to WPS Office for a Lightweight, Freeze-Free Experience

Troubleshooting complex VBA crashes in Microsoft Access can be frustrating and time-consuming. While Access handles databases, if you frequently encounter freezing issues across the broader Microsoft Office suite, it might be time for a change. WPS Office is a highly compatible, free alternative that provides a fast and stable environment for all your word processing, spreadsheet, and presentation needs.

  1. 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install WPS Office: Run the downloaded installer and follow the quick on-screen instructions to set up the software.
  3. 3. Open Your Office Files: Launch WPS Office and directly open your existing Word, Excel, or PowerPoint files without losing formatting or data.
Lightweight architecture ensures stable performance without frequent application freezingFull format compatibility with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx)Completely free to use with all essential office features includedFamiliar tabbed interface allows you to migrate seamlessly with zero learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why does Access VBA freeze specifically on the OpenRecordset line?

The OpenRecordset line is where the Access database engine actually attempts to execute the compiled SQL statement and retrieve data. If the underlying data is corrupted, locked by another process, or violates query parameters (like unexpected Nulls), the engine can hang indefinitely while trying to resolve the invalid request.

How do I view the Immediate Window to debug my SQL in Access?

While inside the VBA Editor (which you can access by pressing ALT + F11), press CTRL + G on your keyboard. This will open the Immediate Window at the bottom of the screen, where your 'Debug.Print' outputs will appear.

Can creating temporary queries via CreateQueryDef bloat my database?

Yes. Repeatedly creating and deleting QueryDefs can leave behind orphaned data pages, causing your Access database file (.accdb or .mdb) to bloat in size over time. It is highly recommended to regularly run the 'Compact and Repair' utility to optimize database performance.