Add up fields within a Form

P

Pass-the-reality

I have a form (frmTesterInfo). Within the form, I have 4 text boxes. The
text boxes are Total Executed, P, RB and FB. I want the text box Total
Executed to add up the data that is keyed into P, RB and FB. I tried to
create a Macro (SetValue) and I could not get it to work. What is the
easiest way to get these fields to add up. Plus, I need to be able to
store the Data in the table, That is a MUST. How can I get this to work?
 
J

Jeff Boyce

If you MUST store a calculated value in a table, you MUST create a procedure
that ensures your data's integrity. If any of the components (or the stored
total) is modified, either via forms or directly in the table or via code,
YOU are responsible for ensuring that the calculation/re-calculation takes
place, and all four values are still in synch.

Or you could take a somewhat easier approach and use a query to derive the
calculated value whenever you need it, and only store the raw values.

To get the form (not the table) to display the calculated value, you could
use an unbound textbox, and in the Control Source property, put something
like:

= [P] + [RB] + [FB]

You may need to re-calculate the form after any change to any of those three
components.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
M

molsonexpert

I would create an unbound text box whose control source is the addition of
the amounts in the four text boxes. Why must the data be stored in a table
(I can tell you right now, there are very few (if any) valid reasons why
this should be done)? You could run a mcro or some VBA script that updates
that field in the table with that of the unbound text box, but again, a bad
idea. What if the program crashes, for example, the field doesn't get
update?
 
Top