Others

Save and Close a Microsoft Access Form and Its Popup with VBA

Steven ParkerSteven Parker Nov 13, 2026 869 views

Question details

Save record edits and close both a main Microsoft Access form and its popup from a command button on the popup.

Product
Microsoft Access
Device & OS
not provided
Scenario
The main form is frmInspection, and the popup is fdlgMand. The same popup may also be used with another main form, such as frmDefect.
Observed behavior
The desired result is for the popup button to save the main form's current record, close the main form, and then close the popup.
Before you start

Confirm that frmInspection and fdlgMand are the actual form object names and that the main form is open. On the popup's command button, set the On Click property to [Event Procedure]; required fields and validation rules must be satisfied before a record can be saved.

Solution 1Recommended

Save and close frmInspection from the popup button

Use this approach when fdlgMand always belongs to frmInspection.

The acSaveNo argument controls whether Access saves changes to the form object's design; it does not mean discard record edits. Explicitly saving a dirty record before closing makes the save action clear and lets validation errors stop the procedure.

1
Open the button's click procedure

Open fdlgMand in Design View, select the command button, and open its Property Sheet. On the Event tab, set On Click to [Event Procedure], then click the ellipsis button to open the VBA editor.

2
Add the save-and-close code

Insert the following inside the button's existing Click procedure: If Forms("frmInspection").Dirty Then Forms("frmInspection").Dirty = False End If DoCmd.Close acForm, "frmInspection", acSaveNo If Not CurrentProject.AllForms("frmInspection").IsLoaded Then DoCmd.Close acForm, "fdlgMand", acSaveNo End If

3
Test the action with a valid record

Save the VBA changes, open frmInspection in Form View, edit a valid record, and open fdlgMand. Click its command button and confirm that the record is saved and both forms close. Also test a missing required field: correct any validation error before trying again.

Save and close frmInspection from the popup button
Design saving and record saving are different: The basic close commands are DoCmd.Close acForm, "frmInspection", acSaveNo followed by DoCmd.Close acForm, "fdlgMand", acSaveNo. The explicit Dirty check adds a deliberate record save. Avoid On Error Resume Next here, because it can hide a failed save.
Free Microsoft Office alternative

Use WPS Office for Reports Exported from Access

WPS Office is a free, lightweight, easy-to-use alternative for working with Office documents and Access data exported to spreadsheets. Its familiar interface and Microsoft Office format compatibility make it easy to move report work to WPS, but it does not run Access forms or fix Access VBA.

Review Access data after exporting it to an Excel workbook.Work with Microsoft Excel .xlsx and .xls files and Word .docx documents.Use a familiar spreadsheet interface for sorting, filtering, and summarizing exported records.Keep Access form automation in Microsoft Access while using WPS for spreadsheet reporting.
QA img-9

Frequently Asked Questions

Does acSaveNo discard changes to the current record?

No. In DoCmd.Close, acSaveNo refers to saving the form object's design changes, not record edits. To explicitly save the current record first, use If Forms("frmInspection").Dirty Then Forms("frmInspection").Dirty = False.

Why does the popup button show no activity?

Open fdlgMand in Design View and check the button's Property Sheet > Event > On Click. It must be set to [Event Procedure] and linked to the correct Click procedure. If the code reads Me.OpenArgs, make sure the popup was opened with OpenArgs:=Me.Name from the main form. Remove On Error Resume Next while troubleshooting so errors are visible.

Can one popup close either frmInspection or frmDefect?

Yes. In each main form's VBA module, open fdlgMand with DoCmd.OpenForm FormName:="fdlgMand", WindowMode:=acDialog, OpenArgs:=Me.Name. The popup can read Me.OpenArgs and use that name in Forms(parentForm) and DoCmd.Close.

What happens if required fields are missing when I save?

Setting the form's Dirty property to False attempts to save the record and triggers applicable validation. If saving fails, the procedure should stop rather than continue closing forms. Fill in the required fields or correct the invalid values, then click the button again.

Can WPS Office open and run these Access forms?

No. WPS Office is not a replacement for the Access database application and does not run .accdb forms or their VBA procedures. In Access, use External Data > Export > Excel to export suitable data, then open the exported workbook in WPS Spreadsheet.