how to act on changes in subforms (but take the action in the main form).

  • Thread starter Thread starter Darcy
  • Start date Start date
D

Darcy

I have a form that allows me to edit the records of a table.

One of the fields is calculated so I have to calculated it every time the
user makes a change.

The change might take place in a subform or in the main form.

What event handler should I use?

AfterUpdate and BeforeUpdate don't fire when I make changes in the subforms.
(Bummer).

Instead of fiddling around with all these silly events, is there a way of
just running the calculation every time I leave the record to go to a new
record?

Thanks in advance.
 
Darcy,

I am not sure where you got the idea that "AfterUpdate and BeforeUpdate
don't fire when I make changes in the subforms". This is not true.

However, if you don't want to fiddle around, here's the best solution...
Delete the calculated field from the table. (Hint: it should never have
been there in the first place). Then, whenever you need this value for
your purposes of form or report, calculate it "on the fly", either in
the query that the form or report is based on, or within the control
source of an unbound control on the form or report itself.
 
Thanks for the suggestions.

When I go into a form (with sub forms) and I put the following into the
AfterUpdate event handler: msgbox "afterupdate"

The message box comes up whenever I make a change in the form. If I make a
change in a sub form (there are about 5 of them on different tabs), the
msgbox of the main form does not come up.

Is there an extra step to make sure that changes in subforms cause the
afterupdate of the main form to fire? Or are there things that I could have
done to stop it from happening? (I've done very little programming or
changing of properties on the said form).

If I follow your advice to do the calculation and not store it in the table,
that would still be ok but I'm still left with my original problem. I need
to update the value when ever a change is made in the form or subform.

Darcy
 
Darcy,

Ah, ok, I misunderstood you. Changing a value on a subform does not
trigger the Before Update or After Update events of the main form. But
it does trigger these events of the subform, and of the control on the
subform.

If your calculation is done in a calculated field within the query that
your form is based on, you can put this code, as applicable...
Me.Recalc
or...
Me.NameOfSubform.Form.Recalc
or...
Me.Parent.Recalc
.... on the AfterUpdate event of any other control whose value affects
the calculation.
 
Back
Top