Calculated field write to a table - How?

  • Thread starter Thread starter SteveL
  • Start date Start date
S

SteveL

I have a calculated field on a form. I need the value of
this calculation to write to a table field. How can I do
this?

--Steve
 
I have a calculated field on a form. I need the value of
this calculation to write to a table field. How can I do
this?

--Steve

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or just as you're now doing it -
in the control source of a Form or a Report textbox.

If you REALLY REALLY want to do it wrong, realizing that the
calculated value stored *will* be wrong in some records at some point,
you can use the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
Me!txtBadlyDesignedField = Me!txtCalculatedField
End Sub

But I'm curious to know why you feel that it's essential to do
something that experienced developers all avoid like poison sumac!

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top