Forms - subforms - after update event

  • Thread starter Thread starter DKliem
  • Start date Start date
D

DKliem

For my question, I have a main form, MyMainForm, and a subform, MySubForm,
which are based on tables with a one-to-many relationship. The main form
shows records from the "one" side of the relationship; the subform shows
records from the "many" side of the relationship. The main form has a
true/false field, called MyTrueFalseField. The subform has a text field
which is called MyTextField.



My question is, when the true/false field in the main form is true, I want
all data in the subform to be deleted. What code can I insert into the
After Update Event to do this?



Vise Versa, if data is entered into the subform, I would like the true/false
field in the main form to be set to true.



Thank you for your time.
 
You could run a Delete Query on the subforms record source to delete all of
the records. You'll need to put the same criteria on the record source as is
currently filtering the subform, including the value of the Child/Parent
link fields.
Vise Versa, if data is entered into the subform, I would like the
true/false
field in the main form to be set to true.

This would immediately delete the data again. Do you mean set the check box
back to False? Why are you using a checkbox instead of a button? If you're
going to delete the item by just checking the checkbox, then it would be
just as easy to click a button. The checkbox wouldn't be checked very long,
just a second or two while the delete query runs, then it would be set back
to false again. However, you could combine the checkbox and a button. Have
the Click event of the button check the value of the checkbox before doing
the delete or have the AfterUpdate event of the checkbox enable/disable the
button. This would be kind of a "lock" on the button to prevent it from
accidentally being clicked.

To change the value of the checkbox from the subform, in the subform's
AfterUpdate event try something like:

Me.Parent.MyTrueFalseField = True
 
Thank you Wayne,

As clear and careful as I tried to be, I misspoke. You're correct. When
there is data in the subform I want the checkbox to be = False.

The purpose of the checkbox isn't to perform an action, it's to record a
response. If the checkbox is true, then there shouldn't be data in the
subform. If there is data in the subform, the checkbox needs to be = False.
It's actually much more complicated than this, which is why I wasn't clear.

I'll give the 'Delete Query' and the 'Me.Parent.MyTrueFalseField = True' a
try.

Thank you for your help.
 
Back
Top