Others

Delete Access Form and Subform Records with VBA

Huda QurayshiHuda Qurayshi Nov 22, 2026 868 views

Question details

Delete records from an Access main form and its related subform.

Delete Access Form and Subform Records with VBA
Product
Microsoft Access
Device & OS
not provided
Scenario
A VBA procedure should delete related subform records and their parent record from a main form.
Observed behavior
Only one set of records is deleted, depending on the deletion order.
Before you start

Identify the subform control name on the main form and a control on the main form that can receive focus. Check the parent-child relationship and any active filters, because they affect which records will be deleted.

Solution 1Recommended

Delete the Current Parent and Its Subform Records with VBA

Use this approach to delete the displayed child records before deleting the current parent record.

The subform control name can differ from the name of the form it displays. This procedure targets the current parent and the child records visible in its subform; it does not automatically process every parent record.

1
Find the control names

Open the main form in Design View, select the subform control, and check its Name in the Property Sheet. Also note the name of an enabled main-form control that can receive focus.

2
Update the VBA procedure

Open the form's VBA editor and replace the placeholder names in this sequence: Me!NameOfYourSubformControl.SetFocus; DoCmd.RunCommand acCmdSelectAllRecords; DoCmd.RunCommand acCmdDelete; Me!NameOfYourMainFormControl.SetFocus; DoCmd.RunCommand acCmdSelectRecord; DoCmd.RunCommand acCmdDelete. Put each statement on a separate line.

3
Run and check the deletion

Open the form in a view that supports record selection, navigate to the intended parent record, and run the procedure. Confirm any Access deletion prompts and check that the intended parent and child records were removed.

Check the deletion scope: Active filters can limit the subform records selected. The commands also require deletions and record selection to be available in the form's current view.
Free Microsoft Office alternative

Work with Office Files in WPS Office

WPS Office is a free, lightweight alternative for everyday documents, spreadsheets, and presentations. Its familiar interface and Office format compatibility make it easy to move existing files. It does not replace Access or fix Access database relationships.

Review and organize exported database data in WPS SpreadsheetOpen and edit Microsoft Office formats including DOCX, XLSX, and PPTXUse a familiar interface for everyday Office tasksMove existing Office files into a lightweight, free suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the VBA code use Me! for the subform?

Me!NameOfYourSubformControl refers to a named control on the current Access form. Check the control's Name in the main form's Property Sheet; it may differ from the form object's name.

Will selecting all subform records delete children for every parent?

No. The subform normally displays records related to the current parent, and active filters may narrow that set further. Select another parent to work with its displayed child records, or consider a cascade relationship.

Where do I turn on cascade deletes in Access?

Go to Database Tools > Relationships and edit the parent-child relationship. Enable Enforce Referential Integrity and Cascade Delete Related Records, provided Access can enforce the relationship.

Can I delete child records with a query instead?

Yes. Create a DELETE query against the child table and use the linking field as a criterion to target the intended parent's records. Check the criterion carefully before running the query.