Hi,
I want numeric only input for a certain textbox. I can use a ISNUMERIC function to test this, but prefer to use the Keypress event. So far got the following:
It is working alright, except I want to avoid input that has multiple leading zeros, such as 00000 or -00000 (i.e. minus sign with mulitple leading zeros). Anyone knows how to catch this?
Thanks
I want numeric only input for a certain textbox. I can use a ISNUMERIC function to test this, but prefer to use the Keypress event. So far got the following:
Code:
Private Sub txt_Position_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8 ' backspace
Case Asc("1") To Asc("9")
Case Asc("-")
If InStr(1, Me.txt_Position.Text, "-") > 0 Or Me.txt_Position.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.txt_Position.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Asc("0")
[COLOR=red]' What do I do here?[/COLOR]
Case Else
KeyAscii = 0
End Select
End Sub
It is working alright, except I want to avoid input that has multiple leading zeros, such as 00000 or -00000 (i.e. minus sign with mulitple leading zeros). Anyone knows how to catch this?
Thanks