How to Diagnose High Memory Usage in Microsoft Access VBA
Question details
The user needs to diagnose and resolve gradual memory consumption and 'Out of Memory' errors occurring in a long-running Microsoft Access VBA application connected to SQL Server.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Running a long-duration Microsoft Access VBA application that interacts with SQL Server.
- Observed behavior
- The application gradually consumes memory over time, eventually resulting in an Out of Memory error due to potential memory leaks, unreleased objects, or unusually long operations.
Before diving into the VBA code, ensure your Microsoft Access version and SQL Server ODBC drivers are fully updated, as some underlying memory leaks are resolved in newer software patches.
Review VBA Code for Unreleased Objects
Identify and explicitly close recordsets, database connections, and forms to free up memory during long operations.
VBA does not have an automatic garbage collector that runs instantly. If objects are opened in a loop but never closed, memory is continually consumed until the application crashes.
Press ALT + F11 in Microsoft Access to open the Visual Basic for Applications (VBA) editor.
Search your code for any instantiated Recordsets, QueryDefs, Workspace, or Database objects (e.g., using 'Set rs = CurrentDb.OpenRecordset(...)').
Ensure that every object opened has a corresponding '.Close' method called before the function or loop ends (e.g., 'rs.Close').
Explicitly release the memory by setting the object variables to Nothing (e.g., 'Set rs = Nothing') immediately after closing them.

Isolate the Issue with a Minimal Reproducible Example
Strip down the application to the smallest possible code block that still produces the memory error to pinpoint the root cause.
Apply Workarounds and Review Performance Guidelines
Implement temporary application restarts and optimize queries according to Microsoft's performance guidelines to manage memory loads.
Looking for a Lightweight Alternative to Microsoft Office?
If Microsoft Access VBA memory issues are slowing down your system, you might benefit from a lighter, more streamlined office suite for your daily document and data tasks. WPS Office provides a free, highly compatible alternative to Microsoft Office, ensuring smooth performance without the heavy resource usage.
- 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 setup file and follow the on-screen instructions to complete the fast, lightweight installation.
- 3. Open Your Files Seamlessly: Launch WPS Office and immediately open your existing Microsoft Office files without worrying about formatting loss.

Frequently Asked Questions
Why does my Access VBA code eventually give an 'Out of Memory' error?
This error typically occurs when VBA objects like Recordsets, forms, or database connections are opened inside a loop but never explicitly closed or set to 'Nothing'. Over time, this creates a memory leak, causing the application to consume all available system RAM until it crashes.
Does restarting Microsoft Access fix the memory leak?
Restarting Access is only a temporary workaround. Closing the application flushes the RAM and clears the immediate out-of-memory error, but the memory leak will occur again when you rerun the process unless the underlying VBA code is fixed to properly release objects.
How do I properly release an object in Access VBA?
To properly release an object and free up memory, you should first close the object using the '.Close' method (if applicable, such as for Recordsets) and then release the memory by setting the object variable to 'Nothing' (e.g., Set myRecordset = Nothing).




