Sum multiple fields on a form using access 2007

  • Thread starter Summing multiple fields on a form
  • 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?
 
J

John W. Vinson

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.
 
S

Summing multiple fields on a form

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top