Others

How to Capture Old Access Form Values Before Updating a Record

John WilsonJohn Wilson Oct 26, 2026 868 views

Question details

The user needs to record the previous values of specific bound controls into an audit table before saving changes to a form.

How to Capture Old Access Form Values Before Updating a Record
Product
Microsoft Access
Device & OS
not provided
Scenario
Tracking historical data changes in an Access database by capturing old form values upon modification.
Observed behavior
Whenever a user modifies fields such as MachSerialNo, ProjectAssetNo, or ProjectLocation in the MachHist form, the old values must be automatically inserted into the TblMachDataChange table along with the current FormNo.
Before you start

Ensure you have a recent backup of your Access database before modifying VBA code, and verify that the 'TblMachDataChange' table is correctly structured to receive the historical data fields.

Solution 1Recommended

Use the Form's BeforeUpdate Event with VBA

The most robust and standard method is to trigger a VBA script during the form's BeforeUpdate event to compare current values against their .OldValue properties.

The BeforeUpdate event is the ideal place for data validation and auditing. Because the record has not been saved to the underlying table yet, Access still retains the original data in the .OldValue property of bound controls.

1
Open the Form in Design View

Right-click the 'MachHist' form in your Access Navigation Pane and select 'Design View'.

2
Access the BeforeUpdate Event

Open the Property Sheet (press F4), click on the 'Event' tab, find 'Before Update', choose '[Event Procedure]' from the dropdown, and click the builder button (...) to open the VBA editor.

3
Write the Comparison Logic

In the VBA editor, write conditional statements to compare `Me.MachSerialNo.Value` with `Me.MachSerialNo.OldValue`. Repeat this logic for `ProjectAssetNo` and `ProjectLocation` to track whether any value actually changed.

4
Construct the SQL Insert Statement

If changes are detected, build a SQL INSERT string that maps the `.OldValue` of each field to the corresponding columns in `TblMachDataChange`, ensuring you include `Me.FormNo`.

5
Execute the SQL Statement

Run the SQL command using `CurrentDb.Execute strSQL, dbFailOnError` to safely insert the historical record before the new data is committed to the database.

Handle Nulls and Special Characters: Be sure to handle Null values explicitly (e.g., using the Nz function) and escape apostrophes in text values by replacing single quotes to prevent SQL syntax errors during the insert.
Free Microsoft Office alternative

Looking for a Lightweight Microsoft Office Alternative?

While WPS Office does not include a database application like Access, it provides powerful, free, and highly compatible alternatives for Word, Excel, and PowerPoint. If you want to streamline your document, spreadsheet, and presentation tasks without heavy subscription fees, WPS Office is an excellent choice.

Fully compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx) formats.Lightweight design that runs smoothly on older and newer devices alike.All-in-one tabbed interface for managing documents, spreadsheets, and PDFs in a single window.
microsoft office alternative - wps office

Frequently Asked Questions

What is the difference between .Value and .OldValue in Access VBA?

The `.Value` property represents the current data entered in the control, even if it hasn't been saved yet. The `.OldValue` property retains the original data from the bound table field before the user started editing the current record.

Why use the BeforeUpdate event instead of AfterUpdate for capturing old values?

The BeforeUpdate event triggers before the database commits changes to the table. This allows you to safely access the `.OldValue` property. In the AfterUpdate event, the old values have already been overwritten and are no longer accessible.

How do I handle Null values when building the SQL INSERT statement?

You can use the `Nz()` function in VBA to convert Null values into empty strings (`""`) or zero, preventing errors when constructing your SQL string. Alternatively, explicitly check for `IsNull()` before appending the value.

What does dbFailOnError do in CurrentDb.Execute?

Adding the `dbFailOnError` option ensures that if the SQL INSERT statement fails (e.g., due to a data type mismatch or missing table), VBA will generate a run-time error rather than failing silently, which helps you easily debug the issue.