Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating a total value 1

Status
Not open for further replies.

PaveFE

Programmer
Jul 5, 2005
33
Hi,

I've looked to see if this was mentioned elsewhere, but had no luck.
How do I calculate a sum for all values entered in a series of text boxes? For example (Aviation related):
The form built from a table has say 4 fields where the user puts a value in each field, a number based on risk factor for each (Weather, Maintenance, Mission, Man). I want the fifth (last) field to automatically total all of the previous fields and not be changed (i.e. the total risk factor). In Excel this would be easy, but I'm not familiar with how it can be done in Access.

Thanks in advance.
VAD
 
Go to properties of your Fifth field
Go to the following:

Control Source...... = [Field1Name]+[Field2Name]+[Field3Name]+[Field4Name]

Locked.....Yes
 
Thanks, I'll give it a whirl. I figured it was something easy, but I just couldn't think of it.

VAD
 
Well, I did as you said, but it didn't work. When I switched to the Form view, here's what it showed in the fifth box:
#Name?

Not sure why it isn't working, any ideas?

VAD
 
how are ya PaveFE . . .

You need to compensate for no data entry in any of the textboxes . . .
Code:
[blue]= Nz([Field1Name])+Nz([Field2Name])+Nz([Field3Name])+Nz([Field4Name])[/blue]

Calvin.gif
See Ya! . . . . . .
 
Okay, here's more of what I got.

I used the formula you stated above, but only used two field names, which worked somewhat. I put a 1 in the first field and a 1 in the second field. The last field has the formula, but it didn't add them up per say, it gave me a value of 11 vs. 2.
I need the last field to total the numbers up in all previous fields and give a SUM. Is this possible?

Thanks,

VAD
 
how are ya PaveFE . . .

You need to compensate for no data entry in any of the textboxes . . .
CODE
= Nz([Field1Name])+Nz([Field2Name])+Nz([Field3Name])+Nz([Field4Name])"

What is the Nz for?

Thanks,

Vince
 
PaveFE . . .

In the AfterUpdate event of the four fields involved, copy/paste the folowing:
Code:
[blue]   Me.reCalc[/blue]
Then let me know . . .

As to your question Vince:
PaveFE said:
[blue]What is the Nz for?[/blue]
A [blue]null[/blue] is basically what you have when there's [blue]no data entry[/blue] in a textbox. Nulls wreck havoc in calculations where [blue]1 null textbox[/blue] causes the entire formula to [blue]return NUll![/blue]

[blue]Nz[/blue] returns zero if the expression (textbox in this case) is NUll!

Calvin.gif
See Ya! . . . . . .
 
A null is basically what you have when there's no data entry in a textbox. Nulls wreck havoc in calculations where 1 null textbox causes the entire formula to return NUll!

Nz returns zero if the expression (textbox in this case) is NUll!"

Gotcha, however, I think my original problem where I was getting the #Name? was because I had something misspelled.

My next problem is still there though, it does not sum the values (i.e. 1+1=2), instead, it just places all the values entered in the box next to each other (i.e. 1,1,1 = 111).
I want something similar to what excel does, where you can add the sum of several cells (in this case numbers entered text boxes).

Thanks,

Vince
 
Regarding your 1+1=11, most likely your fields are defined as strings (not numbers).

I believe this would work:

Val(Nz([Field1Name],0))+Val(Nz([Field2Name],0))+Val(Nz([Field3Name],0))+Val(Nz([Field4Name],0))

 
Update!
I got it to work by using the =[field1]+[field2}, I found out one of the field names was wrong and that's why I was getting the #Name?. However, now that it is working, I have another problem.
Now that I'm able to get that box to add all the values, I now need to have another box to store that value in the table. So, I have my "formula" box hidden, and I need another box that will be stored in the table to display the value that was calculated. How do I make one text box display the value that is calculated in the other?

Thanks,

Vince
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top