In your field's keypress event, place the following:
Code:
Dim wasKeyGood As Boolean
wasKeyGood = CheckKeyPress(KeyAscii)
If Not wasKeyGood Then
KeyAscii = 0
your_field_here.SelStart = 0
your_field_here.SelLength = Len(your_field_here)
Exit Sub
End If
then create a code module that does this:
Note: in my example, the user is unable to enter a single or double quote.
Code:
Public Function CheckKeyPress(nASCIIValueofKey As Integer) As Boolean
Dim sTmp As String
CheckKeyPress = True
If nASCIIValueofKey = Asc("'") Or nASCIIValueofKey = 34 Then ' 34 = "
nASCIIValueofKey = 0 ' cancel the character
Beep
CheckKeyPress = False
Else 'the user has pressed some key that we want
'nothing, we will allow these characters
End If
End Function
[This message has been edited by JHausmann (edited 10-12-1999).]