Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding integers (2000)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Adding integers (2000)

    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.
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding integers (2000)

    Try:

    Dim X As Integer

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

    Msgbox X

  4. #4
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding integers (2000)

    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

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding integers (2000)

    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
    Francois

  6. #6
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding integers (2000)

    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.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding integers (2000)

    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>post 412737</post#> for instructions.

Posting Permissions

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