Others

Save and Close a Microsoft Access Parent Form from a Subform

Khadija KhanKhadija Khan Nov 20, 2026 869 views

Question details

Save the current parent record and close its form from a reusable subform without hard-coding the parent form name.

Save and Close a Microsoft Access Parent Form from a Subform
Product
Microsoft Access
Device & OS
not provided
Scenario
A reusable subform contains buttons that open related forms and needs to close whichever parent form hosts it.
Observed behavior
The subform button should save the parent record and close the hosting form by referring to its name dynamically.
Before you start

Open the subform in Design View and identify the button that should close the parent form. The code must run while the form is embedded as a subform so that Me.Parent refers to its hosting form.

Solution 1Recommended

Save the parent record and close the parent form with VBA

Use the subform's Parent property to save the hosting form's current record and close it without specifying its name.

1
Open the button event

In the subform's Design View, select the button. On the Property Sheet's Event tab, set On Click to [Event Procedure], then select the ellipsis and choose Code Builder if prompted.

2
Add the save and close code

Inside the button's Click event procedure, add: If Me.Parent.Dirty Then Me.Parent.Dirty = False End If DoCmd.Close acForm, Me.Parent.Name

3
Test the button

Save the subform, open a parent form that hosts it, edit the parent record, and click the button. Confirm that the parent form closes and the edit is saved.

Save the parent record and close the parent form with VBA
Saving the record: Setting the parent form's Dirty property to False saves its current record. If validation prevents the save, resolve the validation error before closing. If the parent record has already been saved, another Dirty check is unnecessary.
Free Microsoft Office alternative

Use WPS Office for Everyday Documents and Spreadsheets

WPS Office is a free, lightweight alternative for everyday office work, with a familiar interface and Microsoft Office format compatibility to help you migrate documents and spreadsheets. It does not run Access forms or replace the Access VBA solution above.

Create and edit documents, spreadsheets, and presentations in a familiar interface.Open and save common Microsoft Office formats, including DOCX, XLSX, and PPTX.Use WPS Spreadsheets for tabular data when an Access database is not required.Work with a free, lightweight office suite.
microsoft office alternative - wps office

Frequently Asked Questions

How do I close the parent form without knowing its name?

In the subform's button Click event, use DoCmd.Close acForm, Me.Parent.Name. The Parent property refers to the form hosting the subform.

Does Me.Dirty save the parent record from a subform?

No. In the subform's code, Me.Dirty refers to the subform's current record. Use Me.Parent.Dirty to check or save the parent form's current record.

What if the parent record has already been saved?

If your code has already successfully saved the parent record, you can close the form with DoCmd.Close acForm, Me.Parent.Name without checking its Dirty property again.

Will the code work when the subform is opened on its own?

No. Me.Parent requires the form to be hosted as a subform. Open it inside a parent form before running the button code.