by Jon Hickman (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 15th February 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Prevents special characters from being entered into a textbox
'Private Sub txtLastName_KeyPress(KeyAscii As Integer)
'KeyAscii = Prevent_Special_Chars(KeyAscii)
'End Sub
'function can be adjusted to allow/disallow any values you want
Public Function Prevent_Special_Chars(KeyAscii As Integer) As Integer
'prevents a user from entering a special characters and numbers into a control from where the function is called
If (KeyAscii >= 33 And KeyAscii <= 64) Or (KeyAscii >= 91 And KeyAscii <= 96) Or (KeyAscii >= 123 And KeyAscii <= 126) Then
Prevent_Special_Chars = 0
Else
Prevent_Special_Chars = KeyAscii
End If
End Function