Others

How to Temporarily Remove and Restore Access Form Record Sources

Adam DavisAdam Davis Nov 4, 2026 870 views

Question details

The user needs to dynamically remove the record sources from open Microsoft Access forms to perform backend table replacements, and then restore the original record sources while preserving the exact screen positions of the forms.

How to Temporarily Remove and Restore Access Form Record Sources
Product
Microsoft Access
Device & OS
not provided
Scenario
A database developer needs to release table locks by clearing the RecordSource of open forms via VBA, replace the underlying table, and rebind the forms without losing the users' UI layouts.
Observed behavior
When changing the record source, the form's screen position, current record position, or active filters may be lost. Additionally, VBA errors occur when trying to write to the WindowLeft and WindowTop properties.
Before you start

Before running VBA scripts that modify form properties or replace backend tables, ensure you have created a complete backup of your Access database to prevent accidental data loss or corruption.

Solution 1Recommended

Use VBA to Loop Through Forms and Store Properties in Variables

Capture the RecordSource, WindowLeft, and WindowTop properties of all open forms into memory before making backend changes, avoiding Design View modifications.

Instead of opening forms in Design View (which can cause locking issues in a multi-user environment), loop through the active Forms collection using VBA at runtime.

Because WindowLeft and WindowTop are read-only properties, you must read them into variables and later restore the form's position using the DoCmd.MoveSize method.

1
Declare storage variables

In your VBA module, declare arrays, a Collection, or a custom class to store the Name, RecordSource, WindowTop, and WindowLeft properties of each open form.

2
Loop through open forms

Use a 'For Each' statement to loop through the Access.Application.Forms collection.

3
Store properties and clear RecordSource

For each form, save its current properties to your variables, then set its RecordSource property to an empty string ("") to release the table lock.

4
Perform table operations

Execute your backend table replacement or update procedures while the forms are unbound.

5
Restore RecordSource and screen position

Loop through your variables, set each form's RecordSource back to its original SQL string or table name, and use 'DoCmd.MoveSize WindowLeft, WindowTop' to restore its exact screen coordinates.

Use VBA to Loop Through Forms and Store Properties in Variables
Preventing Screen Flicker: Wrap your script with Application.Echo False before starting the loop and Application.Echo True at the end to prevent screen flickering while the forms are being updated.
Free Microsoft Office alternative

Simplify Your Document Management with WPS Office

While Microsoft Access is a specialized database tool, you often need to export database reports to spreadsheets or text documents. WPS Office is a highly compatible, free alternative to Microsoft Office that easily handles your exported data, spreadsheets, and presentations.

  1. 1. Download WPS Office: Visit the official WPS website to download the free installation package for your Windows, Mac, or Linux device.
  2. 2. Open Exported Data: Launch WPS Spreadsheet and seamlessly open any .csv or .xlsx files generated by your database.
  3. 3. Analyze and Report: Use pivot tables, formulas, and charts in WPS Spreadsheet to visualize and analyze your database extracts without compatibility issues.
Fully compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx) formats.Analyze exported Access database tables smoothly with WPS Spreadsheet.Lightweight application that uses minimal system resources.Built-in PDF toolkit for converting and managing database reports.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a VBA error when trying to set WindowLeft and WindowTop?

WindowLeft and WindowTop are read-only properties in Microsoft Access VBA. You can read them to find out where a form is located, but to change a form's position, you must use the DoCmd.MoveSize method.

Does changing a form's RecordSource trigger VBA events?

Yes. Modifying the RecordSource at runtime can trigger form events such as OnLoad, OnCurrent, and OnResize. Ensure your event handlers include error checking to handle scenarios where the RecordSource is temporarily blank.

Is it better to open Access forms in Design View to change properties?

No. Programmatically opening forms in Design View in a multi-user environment often leads to locking errors and UI flickering. It is a best practice to modify properties like RecordSource dynamically at runtime.

Can I use this method for subforms?

Yes, but you access a subform's RecordSource through the Form property of the Subform control (e.g., Me.SubformControlName.Form.RecordSource). Subforms do not have their own screen position independent of the main form.