Results 1 to 4 of 4
  1. #1
    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. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    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)
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Sep 2007
    Posts
    148
    Missinglinq

    Your suggestion solved my problem. Thank you.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad to help!
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •