# Thread: Sum 2 unbound values

1. Registered User
Join Date
Sep 2007
Posts
148

## Unanswered: Sum 2 unbound values

Hello all and hope some of you can help me with this problem.

1) I have 2 unbound text field in my form: txtNOSCS1 and txtNOSCS2
2) I hav3 a bound text field in my form: NoOfStaff
3) I have set the format of txtNOSCS1 and txtNOSCS2 to "general number" (Don't know if that help or not. I am hoping that Access somehow understand that I want these 2 field to store the data as NUMBER. Well, integer to be exact)

4) Now, I want to add these 2 values (txtNOSC1 and txtNOSC2) up and then store it in my table throught the bounded text box, txtNoOfStaff.

5) This following code will only paste the 2 value together.

Private Sub txtNoOfStaff_Click()
Dim NoOfStaffSum As Integer

NoOfStaffSum = txtNOSCS1 + txtNOSCS2
Me.txtNoOfStaff = NoOfStaffSum

End Sub

That is, if txtNOSCS1 = 20 and txtNOSCS2 = 77, then txtNoOfStaff = 2077.

HOWEVER, if I change the formula NoOfStaffSum = txtNOSCS1 + txtNOSCS2 to NoOfStaffSum = txtNOSCS1 * txtNOSCS2, then I will get txtNoOfStaff = 1540 which is CORRECT

Or, if I change the formula NoOfStaffSum = txtNOSCS1 + txtNOSCS2 to NoOfStaffSum = txtNOSCS1 - txtNOSCS2, then I will get txtNoOfStaff = -57which is CORRECT

It is only the "+" doesn't work.

Thanks

2. Moderator
Join Date
Jun 2005
Location
Richmond, Virginia USA
Posts
2,764
My guess is that you've done nothing to designate these two unbound textbox fields as Numbers, so Access is treating them like text. Try

NoOfStaffSum = Val(txtNOSCS1) + Val(txtNOSCS2)

3. Registered User
Join Date
Sep 2007
Posts
148
Missinglinq

Your suggestion solved my problem. Thank you.

4. Moderator
Join Date
Jun 2005
Location
Richmond, Virginia USA
Posts
2,764