Click to See Complete Forum and Search --> : constrain user keyboard?


tolisss
June 19th, 2001, 09:26 AM
how can i constrain the user keyb to only letters and numbers

thnks

dfwade
June 19th, 2001, 10:54 AM
Paste this code in your Keypress event

[vbocde]
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = OnlyRealText(Keyassic)
End Sub

Public Function OnlyRealText(Key As Integer) As Integer

Select Case Key
Case 48 To 57 'Numeric
OnlyRealText = Key
Case 65 To 90 'UpperCase Letters
OnlyRealText = Key
Case 97 To 122 'LowerCase Letters
OnlyRealText = Key
Case 8, 13 'Backspace and Enter
OnlyRealText = Key
Case Else
Key = 0
End Function
[/vbcode]