Why not use the Exit event rather than the Change event?
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......so when excution reaches emptying the textboxVB: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, the code re-excutes itself one time giving the msgbox wornning again.VB:TextBox4.Value = ""
How can i empty the TextBox without the code re-excuting itself ? ........i triedi alse triedVB:Application.EnableEvent = False.............butVB:Exit Sub![]()
******************
Yours
h
Your Help Is Highly Appreciated
Why not use the Exit event rather than the Change event?
Hi helmekki
Try......
VB: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
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
helmekki
I know that.
Why is it preferable to use the 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
Hi,
Numeric only textbox.VB: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
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks