only allow text - no special characters or numbers

mikkistr

New member
Local time
Today, 07:10
Joined
Oct 9, 2000
Messages
7
How do I not allow a user to enter special characters or numbers in a field on a form - only text. ei a persons name with no numbers or special characters but do allow space or a dash?

Thanks ahead to anyone who can help.
 
If you want to have complete freedom to check for anything & everything, you can check each keystroke.

In the form, put some code behind the "on key down" for the field. For example, to check the field TXT_FIELD:

Private Sub TXT_FIELD_KeyDown(KeyCode As Integer, Shift As Integer)
If PeriodCheck(KeyCode) Then
KeyCode = 0
End If
End Sub

Then set up a function like this one. I'm just looking for periods and hard carriage returns, but you could expand this to look for anything. You will need to find the ANSI code for what you are looking for:

Public Function PeriodCheck(KeyCode As Integer) As Boolean
' Check for nasty little keystrokes
' like periods and carriage returns

'The ANSI code for a period is 190
If KeyCode = 190 Then
MsgBox "You may not enter a period in this field.", vbOKOnly + vbInformation, "INVALID CHARACTER"
PeriodCheck = True
SendKeys "{BS}", False
Else
PeriodCheck = False
End If

'the ANSI code for enter is 13
If KeyCode = 13 Then
MsgBox "Do not format text for this screen by using the Enter key. Formatting is done when the field is printed!", _
vbOKOnly + vbInformation, "INVALID CHARACTER"
PeriodCheck = True
Else
PeriodCheck = False
End If
End Function
 
Thanks...works great!
 

Users who are viewing this thread

Back
Top Bottom