Hi, I am looking for a solution similar to the original
post. I need the value of my calculated control
(ctrlTotalMiles)to be written to the a table field
(TotalMiles) after the calculated control is updated. So:
I think I need to write the updating code in the
after_update event procedure of the control. This way if
the control value is updated, so is the table and the
record is not static. Is this better practice and if so,
what code would do this?
It's better practice to *not store derived data in the table AT ALL*.
The problem is that if the values underlying the calculation are
edited, whether through the Form, through an update query, or any
other means, the value of TotalMiles stored in the table is now
*WRONG*, and there's no obvious way to determine that it is wrong. For
that matter, once a value is stored in TotalMiles, that value itself
can be edited, so that (again) it doesn't reflect the actual sum.
If this redundancy and risk of storing invalid data is acceptable to
you (it sure wouldn't be to me!) then use the Form's BeforeUpdate
event rather than the textbox's AfterUpdate event; the AfterUpdate
event of a calculated control will never fire, since that event fires
only when the user types something into the control.