Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 10-30-2006, 06:18 AM   #1
faizulhu
Registered User
 
Join Date: Oct 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
faizulhu is on a distinguished road
Validation Rule to accept Alphabetical Characters Module Problem

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.

faizulhu is offline   Reply With Quote
Old 10-30-2006, 06:32 AM   #2
Bodisathva
Newly Registered User
 
Bodisathva's Avatar
 
Join Date: Oct 2005
Location: Pennsylvania, US
Posts: 1,274
Thanks: 0
Thanked 7 Times in 7 Posts
Bodisathva is on a distinguished road
look at the IsNumeric function...you'll save time and a lot of code
__________________
nemo surdior est quam is qui non audiet
Bodisathva is offline   Reply With Quote
Old 10-30-2006, 06:38 AM   #3
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,843
Thanks: 56
Thanked 1,046 Times in 1,008 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
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)

gemma-the-husky is offline   Reply With Quote
Old 10-30-2006, 07:07 AM   #4
faizulhu
Registered User
 
Join Date: Oct 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
faizulhu is on a distinguished road
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.

faizulhu is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
My validation rule is being ignored! Fiona H Forms 4 10-01-2007 05:57 AM
Table validation rule - field accepts only A-Z naminder Tables 2 02-09-2006 04:31 AM
Combobox Validation Rule sierra467 Forms 1 01-18-2006 11:23 PM
Validation Rule Violation Message-Disabling jalge Forms 12 08-15-2003 12:30 PM
[SOLVED] VALIDATION PROBLEM BADAVEG Queries 4 03-19-2002 05:55 PM




All times are GMT -8. The time now is 10:32 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World