Hello - I have a form with several sub forms and when one record is deleted from the main form, I would like the records under it to be deleted as well.
This is what I have but most of it comes up with errors as in it shows up red. I got this from a book and have manipulated it to suit my needs but obviously it doesn't work. I have attached my database so you can see what I want to do.
Thanks!
Private Sub cmdDelete_Click()
Dim inAnswer As Integer
Dim strSQL As String
If Me.NewRecord Then
Me.Undo
Else
intAnswer = MsgBox("Are you sure you want to delete this record? This will delete the contact as well as all of its sub records.", _vbQuestion + vbYesNo, "Delete Record")
If intAnswer = vbYes Then
'Delete Children for this record:
strSQL = "DELETE * FROM tblChildren " & _
WHERE Children.ID = " & Me.ID
CurrentProject.Connection.Executre strSQL
'Delete Classes for this record:
strSQL = "DELETE * FROM tblClasses " & _
WHERE Classes.ID = " & Me.ID"
CurrentProject.Connection.Executre strSQL
'Delete Donations for this record:
strSQL = "DELETE * FROM tblDonations " & _
WHERE Donations.ID = " & Me.ID
CurrentProject.Connection.Executre strSQL
'Delete VolunteerInfo for this record:
strSQL = "DELETE * FROM tblVolunteerInfo " & _
WHERE Volunteer.ID = " & Me.ID
CurrentProject.Connection.Executre strSQL
This is what I have but most of it comes up with errors as in it shows up red. I got this from a book and have manipulated it to suit my needs but obviously it doesn't work. I have attached my database so you can see what I want to do.
Thanks!
Private Sub cmdDelete_Click()
Dim inAnswer As Integer
Dim strSQL As String
If Me.NewRecord Then
Me.Undo
Else
intAnswer = MsgBox("Are you sure you want to delete this record? This will delete the contact as well as all of its sub records.", _vbQuestion + vbYesNo, "Delete Record")
If intAnswer = vbYes Then
'Delete Children for this record:
strSQL = "DELETE * FROM tblChildren " & _
WHERE Children.ID = " & Me.ID
CurrentProject.Connection.Executre strSQL
'Delete Classes for this record:
strSQL = "DELETE * FROM tblClasses " & _
WHERE Classes.ID = " & Me.ID"
CurrentProject.Connection.Executre strSQL
'Delete Donations for this record:
strSQL = "DELETE * FROM tblDonations " & _
WHERE Donations.ID = " & Me.ID
CurrentProject.Connection.Executre strSQL
'Delete VolunteerInfo for this record:
strSQL = "DELETE * FROM tblVolunteerInfo " & _
WHERE Volunteer.ID = " & Me.ID
CurrentProject.Connection.Executre strSQL