Validation rule for ALPHA only

  • Thread starter Thread starter Programmer - wannaB
  • Start date Start date
P

Programmer - wannaB

I have a 3 character text field that needs to be set to allow only letters no
numbers, but I can not figure out a way to prevent it from allowing numbers.

Is there a different data type I should use or what is it that I need to
place in the validation rule. I've tried things like
not like "###" and
not like "999"

when I look at the builder there are no fuctions like ISALPHA()

would someone please tell me how I can accomplish this... Thank you
 
You could do it in a form

Private Sub ControlNameHere_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc("1") _
Or KeyAscii = Asc("2") _
Or KeyAscii = Asc("3") _
Or KeyAscii = Asc("4") _
Or KeyAscii = Asc("5") _
Or KeyAscii = Asc("6") _
Or KeyAscii = Asc("7") _
Or KeyAscii = Asc("8") _
Or KeyAscii = Asc("9") _
Or KeyAscii = Asc("0") Then
KeyAscii = 0
End If
End Sub

I know, I know :-) there are other ways but ...
 
Or (as a table validation ) you could build it like this (takes a while)

Not 1 Or "1" Or 2 Or "2" Or 3 Or "3" etc etc etc
 
See if this might help:

Function IsAlpha(strIn As String) As Boolean
'*******************************************
'Purpose: Determine if a character is alpha
' i.e. "a" - "z" or "A" - "Z"
'Inputs: ? IsAlpha("4"),
'Output: False
'*******************************************

Dim i As Integer

i = Switch(Asc(strIn) > 122 Or Asc(strIn) < 65, 1, _
InStr("91 92 93 94 95 96", Asc(strIn)) > 0, 2, _
True, 3)
IsAlpha = IIf(i = 3, True, False)

End Function



Wayne-I-M said:
Or (as a table validation ) you could build it like this (takes a while)

Not 1 Or "1" Or 2 Or "2" Or 3 Or "3" etc etc etc
You could do it in a form
[quoted text clipped - 26 lines]
 
You are correct Wayne, there are other ways of doing this, here is one
of them :-

In the KeyPress event of the Text field enter :-

KeyAscii = Asc(UCase(Chr(KeyAscii)))
If Chr(KeyAscii) Like "[!A-Z.]" And KeyAscii <> vbKeyBack Then
KeyAscii = 0

The first line just converts any lower case letters to capitals (which
may or may not be required). Note that the second line should all be
on one line.

To limit the number of characters to 3 enter AAA in the Input Mask
property of the Text box or set the Field Size property of the field
in the bound table (if there is one) to 3.

The above expression can also be used to only allow digits by changing
the Like function to - "[!0-9]".

HTH

Peter Hibbs.
 
I have a 3 character text field that needs to be set to allow only letters no
numbers, but I can not figure out a way to prevent it from allowing numbers.

Is there a different data type I should use or what is it that I need to
place in the validation rule. I've tried things like
not like "###" and
not like "999"

when I look at the builder there are no fuctions like ISALPHA()

would someone please tell me how I can accomplish this... Thank you

LIKE "[A-Z][A-Z][A-Z]"

will work.

John W. Vinson [MVP]
 
An Input mask of

LLL

The above will ONLY allow letters, and MUST be 3 chars in length.

If you want entery optional, then use

???
 
Thanks to you all, for so many terrific responses!!
What a wonderful wealth.............
==============================
An Input mask of

LLL

The above will ONLY allow letters, and MUST be 3 chars in length.

If you want entery optional, then use

???
 
Back
Top