You need to delete the information in the subform first. You should have
Referential Integrity enforced on the link between the tables for the main
and sub forms, so it won't let you delete the record from the main form as
long as there are associated records in the subform (unless you also set the
link for Cascade Deletes).
To do the delete using a button, run a delete query on the subform's table
then delete the record from the main form.
Example:
strSQL = "Delete * From SubformTable Where ID=" & Me.txtID
'The Me.txtID above is a textbox that has the Master Link field in the main
form
'and ID is the field in the subform's table that matches the Child Link
field.
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "Delete * From MainformTable Where ID=" & Me.txtId
CurrentDb.Execute strSQL, dbFailOnError
'This is similar to the previous one, only now we are deleting from
'the table for the main form. In this case, instead of the query, you
'could also have used
'RunCommand acCmdDeleteRecord