Delete records in subform based on checkbox in parent form (1 Viewer)

Harry Paraskeva

Registered User.
Local time
Today, 06:39
Joined
Sep 8, 2013
Messages
67
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: 113
  • SubformIssue2.jpg
    SubformIssue2.jpg
    38.6 KB · Views: 108

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:39
Joined
Aug 30, 2003
Messages
36,133
Presuming there's a numeric key field on the main form that relates them:

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

Harry Paraskeva

Registered User.
Local time
Today, 06:39
Joined
Sep 8, 2013
Messages
67
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.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:39
Joined
Aug 30, 2003
Messages
36,133
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.
 

Harry Paraskeva

Registered User.
Local time
Today, 06:39
Joined
Sep 8, 2013
Messages
67
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
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:39
Joined
Aug 30, 2003
Messages
36,133
Happy to help!
 

Users who are viewing this thread

Top Bottom