Sum of all TextFields

SBBmaster09

Registered User.
Local time
Today, 14:59
Joined
Apr 26, 2013
Messages
92
How can I add multiple fields?

I have almost 15 textfields with values and i want to get the sum of it. I have a total textfield where the sum of all these fields will be inputted. How can I get the sum not using the

Code:
    'txtAPE.Value = txtAPE11.Value + txtAPE12.Value + txtAPE13.Value + txtAPE14.Value + txtAPE21.Value + txtAPE22.Value + _
                    txtAPE23.Value + txtAPE24.Value + txtAPE25.Value + txtAPE26.Value + txtAPE27.Value + txtAPE28.Value + _
                    txtAPE29.Value + txtAPE210.Value + txtAPE211.Value + txtAPE212.Value + txtAPE31.Value + txtAPE32.Value

because when I retrieve the data the Total textfield display the string text of all the values of the field, not the total.

Thank you.
 
How about using CLng()
Code:
 txtAPE = CLng(Nz(txtAPE11, 0)) + CLng(Nz(txtAPE12, 0)) + CLng(Nz(txtAPE13, 0)) + CLng(Nz(txtAPE14, 0)) + CLng(Nz(txtAPE21, 0)) + CLng(Nz(txtAPE22, 0)) + _
         CLng(Nz(txtAPE23, 0)) + CLng(Nz(txtAPE24, 0)) + CLng(Nz(txtAPE25, 0)) + CLng(Nz(txtAPE26, 0)) + CLng(Nz(txtAPE27, 0)) + CLng(Nz(txtAPE28, 0)) + _
         CLng(Nz(txtAPE29, 0)) + CLng(Nz(txtAPE210, 0)) + CLng(Nz(txtAPE211, 0)) + CLng(Nz(txtAPE212, 0)) + CLng(Nz(txtAPE31, 0)) + CLng(Nz(txtAPE32, 0))
 
Yes it works. Thanks a lot. To verify, I have this percentage field, is it correct If I use this

Code:
txtQAScore.Value = Format((txtAPE.Value / txtTPP.Value), "Percent")

Sometimes it gives me an error if the value is 0/0.


How about using CLng()
Code:
 txtAPE = CLng(Nz(txtAPE11, 0)) + CLng(Nz(txtAPE12, 0)) + CLng(Nz(txtAPE13, 0)) + CLng(Nz(txtAPE14, 0)) + CLng(Nz(txtAPE21, 0)) + CLng(Nz(txtAPE22, 0)) + _
         CLng(Nz(txtAPE23, 0)) + CLng(Nz(txtAPE24, 0)) + CLng(Nz(txtAPE25, 0)) + CLng(Nz(txtAPE26, 0)) + CLng(Nz(txtAPE27, 0)) + CLng(Nz(txtAPE28, 0)) + _
         CLng(Nz(txtAPE29, 0)) + CLng(Nz(txtAPE210, 0)) + CLng(Nz(txtAPE211, 0)) + CLng(Nz(txtAPE212, 0)) + CLng(Nz(txtAPE31, 0)) + CLng(Nz(txtAPE32, 0))
 
So you should perform the division only if they are >0.. Something like..
Code:
If txtTPP > 0 And txtAPE > 0 Then txtQAScore = Format((txtAPE / txtTPP), "Percent")
 

Users who are viewing this thread

Back
Top Bottom