VBA & Macro Problems

Fix an Access Tab Control Cancel Button That Does Not Undo Changes

Muhammad TalhaMuhammad Talha Nov 22, 2026 868 views

Question details

The user needs a Cancel button to discard edits made across an Access form's tabs.

Fix an Access Tab Control Cancel Button That Does Not Undo Changes
Product
Microsoft Access
Device & OS
not provided
Scenario
A form has a tab control, with a subform on the second tab, and a VBA Cancel button that calls Me.Undo.
Observed behavior
Edits on the first tab are canceled, but changes associated with the second tab remain.
Before you start

Open the form in Design View and check whether the second tab contains a subform control. Identify the control's name in its Property Sheet and determine whether edits are still unsaved when Cancel is clicked.

Solution 1Recommended

Undo unsaved edits in the form and subform separately

Use each form's Undo method for its own current, unsaved record.

A subform is a separate form even when its table has a one-to-one relationship with the main table. Moving focus to the subform can save the main form's record, and moving focus back to the main form can save the subform's record. Undo cannot reverse changes that have already been saved.

1
Check the subform control name

Open the main form in Design View, select the subform control on the second tab, and find its Name on the Property Sheet's Other tab. Use the control name, which may differ from the form object's name.

2
Add a subform cancel action

In the subform's Design View, add a Cancel button and set its On Click event to an event procedure. Use `If Me.Dirty Then Me.Undo` to discard unsaved changes to the subform's current record before leaving it.

3
Check the main form's cancel action

Open the main form's Cancel button On Click event procedure and use `If Me.Dirty Then Me.Undo` to discard its current unsaved record. If the main record was saved when focus entered the subform, this action cannot restore its earlier values.

4
Test both tabs

Switch to Form View, edit each tab, and click the relevant Cancel button before leaving the edited form. Reopen the records to verify which changes were discarded and which were saved.

Undo unsaved edits in the form and subform separately
A main-form button may be too late: Clicking a button on the main form can move focus out of the subform and save its record before the button's code runs. Separate Undo calls do not provide an all-or-nothing cancel across already saved records.
Free Microsoft Office alternative

Use WPS Office for Everyday Office Files

WPS Office is a free, lightweight alternative for working with documents, spreadsheets, and presentations. Its familiar interface and Microsoft Office format compatibility make it easy to move everyday files, though it does not fix or replace Access forms and VBA.

Work with spreadsheet data in WPS SpreadsheetsOpen and edit Microsoft Excel, Word, and PowerPoint formats, including XLSX, DOCX, and PPTXUse a familiar interface for everyday office tasksMove compatible Office files into a lightweight suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does Me.Undo not cancel edits on both tabs?

Me.Undo applies to the current unsaved record of the form running the code. If a tab contains a subform, that subform has its own record and Undo method.

Does a one-to-one relationship make the second form part of the main form?

No. A form displayed through a subform control remains a separate form, even if its underlying table has a one-to-one relationship with the main table.

Can Undo restore a record after Access saves it?

No. The form's Undo method discards pending edits to its current record; it does not reverse a save. For an all-or-nothing Cancel action, consider staged editing or another deliberate transaction design.

How can I find the subform control's name?

Open the main form in Design View, select the subform control, and check the Name property on the Property Sheet's Other tab. The control name may differ from the name of the form it displays.