Announcement

Collapse
No announcement yet.

Behaviour of TextBox_Change

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Behaviour of TextBox_Change

    Hi there
    I use TextBox to enter only numbers, but if i enter alpha then the msgbox appears telling me that i must enter numerics, then the code empty the TextBox
    Code:
    Private Sub TextBox4_Change()
    
    If Not IsNumeric(Search.TextBox4) Then
    MsgBox "Only Numeric", vbCritical + vbOKOnly + vbMsgBoxRight, "Wornning"
    TextBox4.Value = ""
    Exit Sub
    End If
    End Sub
    ......so when excution reaches emptying the textbox
    Code:
    TextBox4.Value = ""
    , the code re-excutes itself one time giving the msgbox wornning again.

    How can i empty the TextBox without the code re-excuting itself ? ........i tried
    Code:
    Application.EnableEvent = False
    i alse tried
    Code:
    Exit sub
    .............but
    ******************
    Yours
    h

    Your Help Is Highly Appreciated

  • #2
    Re: Behaviour of TextBox_Change

    Why not use the Exit event rather than the Change event?
    Boo!

    Comment


    • #3
      Re: Behaviour of TextBox_Change

      Hi helmekki

      Try......

      Code:
      Private Sub TextBox4_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
          If Not IsNumeric(Search.TextBox4) Then
              MsgBox "Only Numeric", vbCritical + vbOKOnly + vbMsgBoxRight, "Wornning"
              TextBox4.Value = ""
              End
          End If
      
      End Sub
      Edgar

      Templates & Calculators

      Comment


      • #4
        Re: Behaviour of TextBox_Change

        Hi Norie, (Thank u 4 reply)
        Exit event is trigerred when exit from the TextBox
        i.e after typing a whole text, whereas Change event is trigerred when just type the first vaule to chack the condition...........that is way change is preferable.

        Thank u thoemmes
        ******************
        Yours
        h

        Your Help Is Highly Appreciated

        Comment


        • #5
          Re: Behaviour of TextBox_Change

          helmekki

          I know that.

          Why is it preferable to use the change?
          Boo!

          Comment


          • #6
            Re: Behaviour of TextBox_Change

            Ok Norie,
            cuz the users need speed and need to realise their mistaks at an early stage(in their first entry), specially in long texts or numbers,...... so preferable from their first value entry in the TextBox
            therefore chanhge event offer these whereas Exit not.
            ******************
            Yours
            h

            Your Help Is Highly Appreciated

            Comment


            • #7
              Re: Behaviour of TextBox_Change

              Hi,

              Numeric only textbox.
              Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

              Select Case KeyCode
              Case 48 To 57 ' 0 - 9
              Case 96 To 108 ' 0 - 9 numeric keypad
              Case 67, 189 ' minus and period
              Case 109, 110 ' minus and period numeric keypad
              Case 8 ' backspace
              Case 35 To 39, 46 ' Cursor keys
              Case 187
              If Shift <> 1 Then KeyCode = vbNull
              Case Else
              KeyCode = vbNull
              End Select

              End Sub

              Cheers
              Andy

              Comment


              • #8
                Re: Behaviour of TextBox_Change

                Andy Pope, This is realy a very nice of you

                I thought of it and you posted it..................
                ******************
                Yours
                h

                Your Help Is Highly Appreciated

                Comment

                Working...
                X