Michael:
You can execute an SQL statement in code which deletes all rows from the
table on which the subform is based where the value of the foreign key column
which references the primary key of the parent form's table has the value of
the parent form's current record's primary key. Then you'd requery the
subform control. Say the subform is based on a table Orders with a foreign
key CustomerID which references the CustomerID of the Customers table to
which the parent form is bound, then the code in the button's Click event
procedure would go something like this:
Dim cmd As ADODB.Command
Dim strSQL As String
Dim strMessage As String
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
strMessage = "Delete all records from subform?"
If MsgBox(strMessage, vbQuestion + vbYesNo, "Confirm Deletions") = vbYes
Then
strSQL = "DELETE * FROM Orders " & _
"WHERE CustomerID = " & Me.CustomerID
cmd.CommandText = strSQL
cmd.Execute
Me.YourSubformControl.Requery
End If
Note that YourSubformControl is the name of the control on the main form
which houses the subform, not its underlying form object, unless both have
the same name of course.
Be sure to back up the table on which the subform is based until you are
confident this is doing as expected.
Ken Sheridan
Stafford, England