How do you make it so that you can type backspace in a textbox after you've limited the textbox to only numbers.
Thanks
Printable View
How do you make it so that you can type backspace in a textbox after you've limited the textbox to only numbers.
Thanks
Use the keypress method on the field in qustion to run the following (the second if statement should be modified if you don't want the user to enter "," or "." characters)
Code:
If KeyAscii< Asc("0") Or KeyAscii> Asc("9") Then
If KeyAscii = Asc(",") Or KeyAscii = Asc(".") Or KeyAscii = 8 Then
'nothing, we will allow these characters
Else 'the user has pressed some key other than 0-9 or "," or "." or backspace
KeyAscii = 0 ' cancel the character
field.SelStart = 0
field.SelLength = Len(field)
Beep
End If
End If
Look into the MaxLength property also.
------------------
Tom Young, 14 Year Old
[email protected]
ICQ: 15743470
AIM: TomY10
PERL, JavaScript and VB Programmer
Try this Function. Credit goes to Aaron Young
[/code]
Function Num_Bksp_Only(ByVal KeyAscii As Integer) As Integer
If KeyAscii = vbKeyBack Or IsNumeric(Chr(KeyAscii)) Then
Num_Bksp_Only = KeyAscii
End If
End Function
[code]