How to Fix Microsoft Access Freezing When Opening a Temporary Query
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.

- 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 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.
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.
In your VBA code, insert the line 'Debug.Print strSQL' (or the name of your SQL string variable) just before the 'OpenRecordset' line.
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.
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'.

Inspect Underlying Data for Anomalies
Check if recent changes in the data being queried, such as unexpected nulls or invalid formats, are causing the database engine to hang.
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. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install WPS Office: Run the downloaded installer and follow the quick on-screen instructions to set up the software.
- 3. Open Your Office Files: Launch WPS Office and directly open your existing Word, Excel, or PowerPoint files without losing formatting or data.

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.




