Delete records in subform based on checkbox in parent form

Harry Paraskeva

Registered User.
Local time
Today, 05:11
Joined
Sep 8, 2013
Messages
78
Another issue that is probably easy, but for some reason did not manage to solve it on my own.

I have a parent form and connected to it is a subform. On the parent form I have a checkbox which enables and disables fields on the parent form and also hides the subform, as you can see in the attached screenshots.

What I want to do is when the user unchecks the checkbox, this action also deletes the associated subform records, if there are any.

I'm sure that this can be done with an SQL Delete query in VBA, but for some reason I was not able to figure it out.

Any help will be much appreciated. :D
 

Attachments

  • SubformIssue1.jpg
    SubformIssue1.jpg
    78.6 KB · Views: 147
  • SubformIssue2.jpg
    SubformIssue2.jpg
    38.6 KB · Views: 140
Presuming there's a numeric key field on the main form that relates them:

CurrentDb.Execute "DELETE * FROM TableName WHERE KeyFieldName = " & Me.KeyFieldControl
 
Presuming there's a numeric key field on the main form that relates them:

CurrentDb.Execute "DELETE * FROM TableName WHERE KeyFieldName = " & Me.KeyFieldControl

Some questions:
- Which TableName do I include: The master or the detail table name?
- Same question for the KeyFieldName.
 
The table you want to delete records from, the name of the key field in that table that relates to the main form, and the control on the main form containing the key field.
 
The table you want to delete records from, the name of the key field in that table that relates to the main form, and the control on the main form containing the key field.

Thank you for your clarifications and your advice! :D
 
Happy to help!
 

Users who are viewing this thread

Back
Top Bottom