Sum multiple fields on a form using access 2007

  • Thread starter Thread starter Summing multiple fields on a form
  • Start date Start date
S

Summing multiple fields on a form

I have created a form but have 4 fields on that form that i would like to sum
and store the total in another field created on the structure. What is the
VB code to do that?
 
I have created a form but have 4 fields on that form that i would like to sum
and store the total in another field created on the structure. What is the
VB code to do that?

You've made two mistakes already: building your table wide, not flat, and
trying to store derived data.

You can *display* the sum of four fields by setting a textbox's control source
to

=NZ([field1]) + NZ([field2]) + NZ([field3]) + NZ([field4])

As for storing this value, 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.
 
Thank you..It worked just as you said...THX

John W. Vinson said:
I have created a form but have 4 fields on that form that i would like to sum
and store the total in another field created on the structure. What is the
VB code to do that?

You've made two mistakes already: building your table wide, not flat, and
trying to store derived data.

You can *display* the sum of four fields by setting a textbox's control source
to

=NZ([field1]) + NZ([field2]) + NZ([field3]) + NZ([field4])

As for storing this value, 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.
 
Back
Top