Click to See Complete Forum and Search --> : Question about restriction
cadets45
Nov 2nd, 1999, 10:32 PM
How do you make it so that you can type backspace in a textbox after you've limited the textbox to only numbers.
Thanks
JHausmann
Nov 3rd, 1999, 12:33 AM
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)
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
Compwiz
Nov 3rd, 1999, 03:02 AM
Look into the MaxLength property also.
------------------
Tom Young, 14 Year Old
tom@e-bizinternet.com
ICQ: 15743470
AIM: TomY10
PERL, JavaScript and VB Programmer
Lyla
Nov 3rd, 1999, 09:01 AM
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]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.