Is there a way to limit what can be typed into a textbox? For instance, only numbers or letters?
--
Screaming Fist
A witty saying proves nothing.
Printable View
Is there a way to limit what can be typed into a textbox? For instance, only numbers or letters?
--
Screaming Fist
A witty saying proves nothing.
Hi,
Yes, we can limit the characters in a textbox. Here is an example which limit the characters to Hexadecimal value:
private Sub Text1_KeyPress(KeyAscii as Integer)
Dim strValid as string
strValid = "0123456789ABCDEF" 'valid input
KeyAscii = Asc(UCase(Chr(KeyAscii))) 'force uppercase
If KeyAscii > 26 then 'if not control code
If InStr(strValid, Chr(KeyAscii)) = 0 then
KeyAscii = 0
End If
End If
End Sub
Enjoy yourself and good luck to you.
Gary Ng