why won't this simple code work???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ixnay

    #1

    why won't this simple code work???

    Hello All,

    I am trying to add two Text fields together on my Form. But when I
    run the following code, I get an error that says:

    ___________
    code:
    ___________

    Private Sub sum_click()
    Label.sum = Text1.id1 + Text2.id2
    End Sub


    ___________
    error:
    ___________

    Run-time error '424':
    Object required




    Now, I'm a bit of a newbie, but I've tried everything and can't get
    this to run. Any ideas?

    TIA,

    Mike
  • Suzette

    #2
    Re: why won't this simple code work???

    Try
    Private Sub sum_click()
    Label.sum = val(Text1) + val(Text2)
    End Sub

    The default property for a textbox is .Text so you don't have to use it.
    When using numbers, the textbox contains text so it has to be converted to a
    number. Caution: if you haven't filtered out text on entry, the Val
    function will give you some strange results. Type VAL in your help file to
    see details.

    Suzette

    "Ixnay" <mscgloss@yahoo .com> wrote in message
    news:21326100.0 309241228.30e1f 9fb@posting.goo gle.com...[color=blue]
    > Hello All,
    >
    > I am trying to add two Text fields together on my Form. But when I
    > run the following code, I get an error that says:
    >
    > ___________
    > code:
    > ___________
    >
    > Private Sub sum_click()
    > Label.sum = Text1.id1 + Text2.id2
    > End Sub
    >
    >
    > ___________
    > error:
    > ___________
    >
    > Run-time error '424':
    > Object required
    >
    >
    >
    >
    > Now, I'm a bit of a newbie, but I've tried everything and can't get
    > this to run. Any ideas?
    >
    > TIA,
    >
    > Mike[/color]


    Comment

    • Logit

      #3
      Re: why won't this simple code work???

      Try :

      Private Sub Label1_Click()
      Label1.Caption = Text1.Text + Text2.Text
      End Sub

      If you are wanting to add numerical figures in Text1
      and Text2, that will require other code. Hopefully,
      this will get you started.

      --
      Thanks !

      Jim

      [ logitga@yahoo.c om to reply directly ]

      "If you are living like there is no God ...
      ... you better be right !"



      Comment

      • MooVBuff

        #4
        Re: why won't this simple code work???

        If the contents of the text boxes ar numeric, (12345) then try this:

        Private Sub Label1_Click()
        'Both textboxes contain 12345
        Label1.Caption = Int(Text1.Text) + Int(Text2.Text)
        End Sub

        It should produce ...... 24690

        If the contents of the text boxes are alphanumeric, (abcdef) then try this:

        Private Sub Label1_Click()
        'Both textboxes contain abcdef
        Label1.Caption = Text1.Text & " " & Text2.Text
        End Sub

        It should produce ...... abcdef abcdef


        "Logit" <jdmcjen_remove nospam_@alltel. net> wrote in message
        news:cgpcb.1$K2 2.0@fe05.atl2.w ebusenet.com...[color=blue]
        > Try :
        >
        > Private Sub Label1_Click()
        > Label1.Caption = Text1.Text + Text2.Text
        > End Sub
        >
        > If you are wanting to add numerical figures in Text1
        > and Text2, that will require other code. Hopefully,
        > this will get you started.
        >
        > --
        > Thanks !
        >
        > Jim
        >
        > [ logitga@yahoo.c om to reply directly ]
        >
        > "If you are living like there is no God ...
        > ... you better be right !"
        >
        >
        >[/color]


        Comment

        Working...