How get form field data to write to a table?

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

SteveL

I have a form which is bound to a table. On this form I
have a calculated field. The calculation is the sum of
two other field values. How can I get the value of the
calculated field to write to a specific field in the
table?
 
I have a form which is bound to a table. On this form I
have a calculated field. The calculation is the sum of
two other field values. How can I get the value of the
calculated field to write to a specific field in the
table?

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 have some good reason to do so (for instance, if you WANT to be
able to change one of the fields yet have the sum remain unchanged),
you can use VBA code in the Form's BeforeUpdate event to set a bound
textbox equal to the value in the calculated textbox.
 
-----Original Message-----


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 have some good reason to do so (for instance, if you WANT to be
able to change one of the fields yet have the sum remain unchanged),
you can use VBA code in the Form's BeforeUpdate event to set a bound
textbox equal to the value in the calculated textbox.



.

Do you have a sample of the VBA code I would use to do
this? I realize its is probably NOT the right way to
handle this but I have a specific need to do so and can't
figure out whet the code should be.

--Steve
 
Do you have a sample of the VBA code I would use to do
this? I realize its is probably NOT the right way to
handle this but I have a specific need to do so and can't
figure out whet the code should be.

Let's say you have an unbound textbox txtCalc, and a bound control
txtReal. In the Form's BeforeUpdate event invoke the code builder and
include the line

Me!txtReal = Me!txtCalc
 
Back
Top