• Adding integers (2000)

    Author
    Topic
    #410692

    I am trying to add integers in multiple textboxes and display them in a label just like VB. I am not having any luck. Can anyone help me get started?

    Thanks

    Viewing 2 reply threads
    Author
    Replies
    • #884555

      Your code would look something like this:

      Me.Label1.Caption = Nz(Me.Text1,0) + Nz(Me.Text2,0) + Nz(Me.Text3,0)

      Where Label1 is assumed to be the name of the label and Text1, Text2 and Text3 are textboxes. The Nz functions are necessary because otherwise a Null in any of the textboxes will cause you problems.

      • #884564

        I get a message which says: “The expression ON Exit you entered as the event property setting produced the following error:Expected: Text or Binary”
        I cant figure out what i am doing wrong

        Thanks

        • #884594

          In the Property window, on the line On Exit you should have :
          [Event Procedure]

          In the VBE editor enter for each textbox Charlotte’s code:
          Private Sub Text1_Exit(Cancel As Integer)
          Me.Label1.Caption = Nz(Me.Text1,0) + Nz(Me.Text2,0) + Nz(Me.Text3,0)
          End Sub

          • #885106

            I have the code exactly as you put it. I put the event prodedure for the text boxes ON EXIT property. I even tried putting it as an ON CLICK event for the label. Any help is appreciated.

            • #885110

              Try putting the code in the After Update event of the text boxes, i.e.
              – Select [Event Procedure] in the After Update box in the Properties window
              – Click the … to the right of the dropdown arrow in the After Update box.
              – Make the code look like this, with the appropriate names substituted:

              Private Sub Text1_AfterUpdate()
              Me.Label1.Caption = Nz(Me.Text1, 0) + Nz(Me.Text2, 0) + Nz(Me.Text3, 0)
              End Sub

              – Repeat for the other text boxes
              – Remove the …_Exit event procedures.

              If you still can’t make it work, you might post a stripped down copy of your database. See post 412737 for instructions.

            • #885111

              Try putting the code in the After Update event of the text boxes, i.e.
              – Select [Event Procedure] in the After Update box in the Properties window
              – Click the … to the right of the dropdown arrow in the After Update box.
              – Make the code look like this, with the appropriate names substituted:

              Private Sub Text1_AfterUpdate()
              Me.Label1.Caption = Nz(Me.Text1, 0) + Nz(Me.Text2, 0) + Nz(Me.Text3, 0)
              End Sub

              – Repeat for the other text boxes
              – Remove the …_Exit event procedures.

              If you still can’t make it work, you might post a stripped down copy of your database. See post 412737 for instructions.

          • #885107

            I have the code exactly as you put it. I put the event prodedure for the text boxes ON EXIT property. I even tried putting it as an ON CLICK event for the label. Any help is appreciated.

        • #884595

          In the Property window, on the line On Exit you should have :
          [Event Procedure]

          In the VBE editor enter for each textbox Charlotte’s code:
          Private Sub Text1_Exit(Cancel As Integer)
          Me.Label1.Caption = Nz(Me.Text1,0) + Nz(Me.Text2,0) + Nz(Me.Text3,0)
          End Sub

      • #884565

        I get a message which says: “The expression ON Exit you entered as the event property setting produced the following error:Expected: Text or Binary”
        I cant figure out what i am doing wrong

        Thanks

    • #884558

      Try:

      Dim X As Integer

      X = CInt(Me![TextBoxName]) + CInt(Me![TextBoxOtherName])

      Msgbox X

    • #884559

      Try:

      Dim X As Integer

      X = CInt(Me![TextBoxName]) + CInt(Me![TextBoxOtherName])

      Msgbox X

    Viewing 2 reply threads
    Reply To: Reply #885110 in Adding integers (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel