Misbehaving text box

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

    Misbehaving text box

    Hi everybody

    I'm using access 2000 and want to enter a value in a bound text box
    using vba.

    The problem is that when I step through my code, everything goes well,
    but when my code is run the text box doesn't do anything.

    This is supposed to be something simple?

    Any help would be appreciated.

    Kind regards

    Jean

  • Rich P

    #2
    Re: Misbehaving text box

    Could you post your code so we could see what is or is not happening?
    You have a text box that is bound to a field on a table. You want to
    programmaticall y enter data into this text box. I am guessing that this
    textbox is something of a calculated or results field. You could use a
    formula in the field or a formula that references a user-defined
    function. Just need to show us the code (the money - whatever).

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • Jeandup

      #3
      Re: Misbehaving text box


      Rich P wrote:[color=blue]
      > Could you post your code so we could see what is or is not happening?
      > You have a text box that is bound to a field on a table. You want to
      > programmaticall y enter data into this text box. I am guessing that this
      > textbox is something of a calculated or results field. You could use a
      > formula in the field or a formula that references a user-defined
      > function. Just need to show us the code (the money - whatever).
      >
      > Rich
      >
      > *** Sent via Developersdex http://www.developersdex.com ***[/color]

      Here's the code as requested.

      Private Sub Weight1_DblClic k(Cancel As Integer)
      On Error GoTo errorhandler
      ActiveXCtl17.Co mmPort = 1
      ActiveXCtl17.Se ttings = "2400,E,7,1 "
      ActiveXCtl17.In putLen = 0
      ActiveXCtl17.Po rtOpen = True
      WeightString = ActiveXCtl17.In putData
      ActiveXCtl17.Po rtOpen = False
      ReadPos = InStr(WeightStr ing, hex02)
      Weight = Mid(WeightStrin g, ReadPos + 2, 7)

      Me.Weight1.Text = Weight (The text box is supposed to display the
      weight. While stepping through te code everything goes well, but when
      the code runs the textbox displays nothing)

      Exit Sub

      errorhandler:
      Resume Next
      End Sub

      Hope you can help me

      Jean

      Comment

      • Rich P

        #4
        Re: Misbehaving text box

        >>
        Private Sub Weight1_DblClic k(Cancel As Integer)
        On Error GoTo errorhandler
        ActiveXCtl17.Co mmPort = 1
        ActiveXCtl17.Se ttings = "2400,E,7,1 "
        ActiveXCtl17.In putLen = 0
        ActiveXCtl17.Po rtOpen = True
        WeightString = ActiveXCtl17.In putData
        ActiveXCtl17.Po rtOpen = False
        ReadPos = InStr(WeightStr ing, hex02)
        Weight = Mid(WeightStrin g, ReadPos + 2, 7)

        Me.Weight1.Text = Weight
        Exit Sub

        errorhandler:
        Resume Next
        End Sub
        <<

        OK. Here is what you need do. First: comment out your error handling.
        I noticed you have a resume next statement. Comment out

        'On Error GoTo errorhandler

        and

        'Resume Next

        You want to see if this code bombs out and at what line it bombs out at
        if it does. If you have an On Error Goto statement you can't see at
        what line the code bombs out at because it goest to the ErrorHandler
        label. The other thing to do is to add a debug statement after

        Weight = Mid(WeightStrin g, ReadPos + 2, 7)
        Debug.Print "*" & Weight & "*"

        The purpose of the "*" is to let you know that you got to the
        Debug.Print statement, in case there is no value in Weight. If the code
        bombs out then uncomment

        On Error GoTo errorhandler

        and change "Resume Next" to

        MsgBox Err.Description

        Read the error statement and post it. Err is the VBA Error object. But
        having a Resume Next statement is pretty risky in some situations.
        There are purposes for Resume Next, and your app may have a legitimate
        reason for it. But for now you need to see if the code is bombing out
        and where.

        I will guess that the code will bomb out and that the problem is related
        to something with ActiveXCtl17. Maybe a setting in the code, or it
        sounds like you have a card reader or some hardware you are reading
        from. Maybe you have a bad serial port connection if this is the case,
        or maybe there is a problem with the Reader or device. If you are using
        an external device is there a way to test it to make sure it is working
        correctly?

        HTH

        Rich

        *** Sent via Developersdex http://www.developersdex.com ***

        Comment

        • Jeandup

          #5
          Re: Misbehaving text box

          Thanks Rich

          I found my problem

          When I step through the code, the serial port reads more information
          than when the code is running by itself. That is why an empty string
          is returned to the text box.

          Jean

          Comment

          • Jeandup

            #6
            Re: Misbehaving text box

            Thanks Rich

            I found my problem

            When I step through the code, the serial port reads more information
            than when the code is running by itself. That is why an empty string
            is returned to the text box.

            Jean

            Comment

            Working...