Calculating the sum of several text boxes

  • Thread starter Thread starter dwkoller
  • Start date Start date
D

dwkoller

Hopefully, this is a simple problem.

On my form, I have several text boxes that contain the dollar value of
different items. I'd like to have a text box that calculates the total
value of the individual items. Suppose my text boxes are: item1_cost,
item2_cost, item3_cost [ these are bound to a cells in a table] and the text
box for the calculated sum is total_cost;

In the expression builder the formulas I've tried are:

=item1_cost + item2_cost + item3_cost
or
=sum(item1_cost +item2_cost+item3_cost)

both of these seem to work when the form is first displayed, using the
values stored in the table. However, when I change the value in either of
the item#_cost text boxes, the calculated sum does not change.

Seems like this should not be difficult, any help appreciated. I've looked
at the Northwind database sample -- I'm still confused.

Thanks!!!

dwk
 
dwkoller said:
Hopefully, this is a simple problem.

On my form, I have several text boxes that contain the dollar value of
different items. I'd like to have a text box that calculates the
total value of the individual items. Suppose my text boxes are:
item1_cost, item2_cost, item3_cost [ these are bound to a cells in a
table] and the text box for the calculated sum is total_cost;

In the expression builder the formulas I've tried are:

=item1_cost + item2_cost + item3_cost
or
=sum(item1_cost +item2_cost+item3_cost)

both of these seem to work when the form is first displayed, using the
values stored in the table. However, when I change the value in
either of the item#_cost text boxes, the calculated sum does not
change.

Seems like this should not be difficult, any help appreciated. I've
looked at the Northwind database sample -- I'm still confused.

Thanks!!!

dwk


So that the total changes whenever you change the value in a component
text box, you will need to do the calculation in the After Update event
of each of the component text boxes.

You should use names for your text boxes that are different from the
underlying fields so Access knows which value to use. e.g. the text
box for item1_cost becomes txtItem1_cost.

The code in the After Update event of each of the component text boxes
would be similar to:

txtTotal_cost = txtItem1_cost + txtitem2_cost + txtItem3_cost

hth

Hugh
 
Back
Top