I worked it out!!! Woo Hoo for me!
To delete a record from a subform using a command button in the parent form.
create a function that:
1. Finds the key field value (intKeyValue) on the subform.
2. Run a delete query that delete's the record from the subforms records where [subform].[keyfield] = intkeyvalue
3. Call the function from both the Click event of the command button and the delete event of the subform.
Here is the code I used:.
Function.
Function deleteContact()
Dim db As Database
Dim intconid As Integer
Dim intDelMsg As Integer
Dim strConNam As String
intconid = Forms![customers].[SF_Contacts]!conID
strConNam = Forms![customers].[SF_Contacts].Form!Name
intDelMsg = MsgBox("Are you sure you want to permanently delete " _
& strConNam, vbYesNo + vbCritical + vbDefaultButton2, _
"Warning"
If intDelMsg = 7 Then
DoCmd.CancelEvent
Exit Function
Else
Set db = CurrentDb
db.Execute ("delete * from T_contacts where [T_contacts].[conid] =" & intconid)
db.Close
Forms![customers].[SF_Contacts].Form.Refresh
Forms!customers.Refresh
End If
End Function
Here is the command button click event..
Private Sub cmdDelCon_Click()
deleteContact
End Sub
Here is the subforms delete event.
Sub Form_Delete(Cancel As Integer)
deleteContact
DoCmd.CancelEvent
End Sub
I hope this is helpfull,
Cheers,
Bretto