Totals

  • Thread starter Thread starter Matthew Ellis
  • Start date Start date
M

Matthew Ellis

I am working on a form with five long integer fields for each record that are totaled in a field called total. right now I have the field's default value on the form set to =Sum([Field1]+[Field2]+[Field3]+[Field4]+[Field5]) It works, kind of......... The value of total doesn't update until you move to a new record. How can I have the total field update as each number is entered in the five other fields? And also, is there a better way to do this than using the default value?
 
Hi Matthew

First of all, you should not be storing calculated data in your table. The
total can easily be calculated in a query, using an expression:
Total: [Field1]+[Field2]+[Field3]+[Field4]+[Field5]

If you store the total, then you run the risk of its getting out of sync
with the composite values.

Secondly, the Sum function is used for summing a field across many records,
not for summing several fields within a single record.

Thirdly, the DefaultValue property applies only to new records. What you
need to do is set the ControlSource of your textbox to:
=[Field1]+[Field2]+[Field3]+[Field4]+[Field5]

Then it will update as you change each value.

Actually, I tell a lie. It will only display a total is ALL the fields
contain a value. To get around this, you must convert any blank fields
(Nulls) to zero using the Nz function:
=Nz([Field1])+Nz([Field2])+Nz([Field3])+Nz([Field4])+Nz([Field5])

Use a similar expression in the query. In fact, you can base yopur form on
the query, not on the table, and bind your textbox to the calculated Total
field.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I am working on a form with five long integer fields for each record that
are totaled in a field called total. right now I have the field's default
value on the form set to =Sum([Field1]+[Field2]+[Field3]+[Field4]+[Field5])
It works, kind of......... The value of total doesn't update until you move
to a new record. How can I have the total field update as each number is
entered in the five other fields? And also, is there a better way to do this
than using the default value?
 
Back
Top