Validation Rule to accept Alphabetical Characters Module Problem (1 Viewer)

faizulhu

Registered User.
Local time
Today, 15:26
Joined
Oct 30, 2006
Messages
15
I created a module based on the instruction on Microsoft's Knowledge Base(KB210385) to create a validation rule to accept only alphabetical characters. The code of the module is given below:

Option Compare Database

Option Explicit
Function IsAlpha(MyString As String) As Integer
Dim LoopVar As Integer
Dim SingleChar As String

LoopVar = 1

If IsNull(MyString) Then
IsAlpha = False
Exit Function
End If

For LoopVar = 1 To Len(MyString)
SingleChar = UCase(Mid$(MyString, LoopVar, 1))
If SingleChar < "A" Or SingleChar > "Z" Then

IsAlpha = False
Exit Function
End If
Next LoopVar

IsAlpha = True

End Function

The module works on my fields but it does not allow any spaces or gaps in the fields which makes it almost useless for my database. So can anyone help me to resolve my problem by giving me the code of the module which will accept alphabets and spaces but not numbers.
 

Bodisathva

Registered User.
Local time
Today, 04:26
Joined
Oct 4, 2005
Messages
1,274
look at the IsNumeric function...you'll save time and a lot of code
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 09:26
Joined
Sep 12, 2006
Messages
15,634
you can build up a valid char string

const validchars = "abcdABCD ?<>" etc

if instr(singlechar,validchars) then etc

(the syntax is probably wrong though, but you get the idea)

you could also use the in operator

if singlechar in ("a..z","A..Z"," ")

(again, the syntax is probably wrong)
 

faizulhu

Registered User.
Local time
Today, 15:26
Joined
Oct 30, 2006
Messages
15
I am a novice user and also could not understand the thing you wanted me to do. can you please be more elaborate and send the entire code.
 

Users who are viewing this thread

Top Bottom