Add new field in table that is the sum of fields in the same table

G

Guest

I have a pretty basic question...can you add a new field to a table (not a
form or data access page) that is the sum of several other fields in the same
table.
Example: Field 5 = Field 1+Field 2+Field 3+Field 4.

Using expression builder, I've been able to do this with no problem with
forms but the values don't store in the database tables, only in the
datasheets and they values are calculated each time.

I'd like the database tables to store the value of the subtotal field, so it
would be great to just have the subtotal field automatically calculated in
the table, once the other values are entered. I've tried inputting the
expression in the default value for the subtotal field but it does not
recognize the other field names.

Any help is greatly appreciated!
 
A

Al Camp

Calculation results should not be stored in your table. Since you
already store the 4 values, you can recalculate/re-derive the sum whenever
it's needed in any subsequent forms or queries or reports.
A classic example would be...
Price * Qty * TaxRate = LineTotal
Since you capture the Price, and Qty, and TaxRate you can always re-derive
the LineTotal when you need it. No need to carry that extra field.
Given a form with a Price and Qty and TaxRate fields, an unbound text
control with a ControlSource of...
= [Price] * [Qty] * [TaxRate]\
will always "display" the correct calculation... even if you change Price,
Qty, or TaxRate.
 
G

Guest

I agree with the other post here wholeheartedly, but just a note on adding a
field. You cannot add a field just by calculating it on a form. You must open
the table in design view, create the additional field, then save the table.
Once this is done, you have a place to put the new information. Actually, you
can add a field using VBA, but that is another whole story in itself.
 

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