Validation rule for ALPHA only

  • Thread starter Programmer - wannaB
  • 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
 
W

Wayne-I-M

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 ...
 
W

Wayne-I-M

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
 
R

raskew via AccessMonster.com

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]
 
P

Peter Hibbs

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.
 
J

John W. Vinson

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]
 
A

Albert D. Kallal

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

???
 
W

WANNABE

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

???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Validation Rule 2
Validation Rule 1
Validation rule for alpha, -, ' 10
Validation Rule For only one Field 2
Validation Rule Modification 7
validation rule 1
validation rule 2
Validation rules - digits & letters only 1

Top