Save and Close a Microsoft Access Parent Form from a Subform
Question details
Save the current parent record and close its form from a reusable subform without hard-coding the parent form name.

- 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.
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.
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.
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.
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
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.

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.

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.




