Loading
Ozgrid Excel Help & Best Practices Forums

Excel Training / Excel Dashboards Reports



Results 1 to 8 of 8

Thread: Behaviour of TextBox_Change

  1. #1
    Join Date
    7th May 2004
    Location
    Libya
    Posts
    619

    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. #2
    Join Date
    14th July 2004
    Posts
    10,542

    Re: Behaviour of TextBox_Change

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

    Excel Video Tutorials / Excel Dashboards Reports


  3. #3
    Join Date
    5th May 2005
    Location
    Bristol, UK
    Posts
    125

    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

  4. #4
    Join Date
    7th May 2004
    Location
    Libya
    Posts
    619

    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

  5. #5
    Join Date
    14th July 2004
    Posts
    10,542

    Re: Behaviour of TextBox_Change

    helmekki

    I know that.

    Why is it preferable to use the change?

    Excel Video Tutorials / Excel Dashboards Reports


  6. #6
    Join Date
    7th May 2004
    Location
    Libya
    Posts
    619

    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

  7. #7
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    Re: Behaviour of TextBox_Change

    Hi,

    Numeric only textbox.[vba]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
    [/vba]

    Cheers
    Andy


  8. #8
    Join Date
    7th May 2004
    Location
    Libya
    Posts
    619

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. InstrRev behaviour
    By AndrewW in forum EXCEL HELP
    Replies: 2
    Last Post: February 28th, 2006, 12:27
  2. .find behaviour
    By AndrewW in forum EXCEL HELP
    Replies: 11
    Last Post: January 30th, 2006, 19:33
  3. textbox behaviour
    By racketeer in forum EXCEL HELP
    Replies: 5
    Last Post: September 17th, 2004, 01:33
  4. Need help on TextBox_Change() trigger
    By manojraj in forum EXCEL HELP
    Replies: 3
    Last Post: June 19th, 2004, 05:10
  5. VBA: Strange Behaviour
    By azizrasul in forum EXCEL HELP
    Replies: 2
    Last Post: July 15th, 2003, 23:35

Bookmarks

Posting Permissions

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