Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Only allowing upper and lower case letters in KeyPress...

Status
Not open for further replies.

JennyPeters

Programmer
Oct 29, 2001
228
0
0
US
I am trying to only allow upper and lower case letters in a KeyPress event of a text box. I can isolate the upper case by using the keyascii < vbKeyA or > vbKeyZ, but can't seem to isolate the lower case, as vbKeyA and vbKeyZ are only for uppercase.

Can can I detect lowercase letters?

Thanks,

Jenny
 
Check against the ASCII value:
A-Z: Chr(65) to Chr(90)
a-z: Chr(97) to Chr(122)
 
This snippet allows only upeer/lowercase letters and the backspace key:

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case Asc(UCase(Chr(KeyAscii)))
Case vbKeyA To vbKeyZ, vbKeyBack
'do nothing
Case Else
KeyAscii = 0
End Select
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top