Delete Access Form and Subform Records with VBA
Question details
Delete records from an Access main form and its related subform.

- 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.
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.
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.
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.
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.
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.
Use Cascade Deletes for Related Access Records
Use a relationship with cascade deletes when deleting a parent should automatically delete all related child records.
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.

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.




