Manufacturing Information Solutions Forum Index Manufacturing Information Solutions
Your Place for Support and Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Test a string for an alphanumeric value

 
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access
View previous topic :: View next topic  
Author Message
BIGmiralli
Frequent Poster


Joined: 17 Apr 2007
Posts: 38
Location: Boston, Massachusetts

PostPosted: Fri May 23, 2008 8:52 am    Post subject: Test a string for an alphanumeric value Reply with quote

Question: In Access, I want to know if a string value contains alphanumeric characters only. How can I do this?


Answer: To accomplish this, you need to create a custom function.

You'll need to open your Access database and create a new module.

Then paste into the new module the following function:

Code:
Function AlphaNumeric(pValue) As Boolean

    Dim LPos As Integer
    Dim LChar As String
    Dim LValid_Values As String

    'Start at first character in pValue
    LPos = 1

    'Set up values that are considered to be alphanumeric
    LValid_Values = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-.0123456789"

    'Test each character in pValue
    While LPos <= Len(pValue)

        'Single character in pValue
        LChar = Mid(pValue, LPos, 1)

        'If character is not alphanumeric, return FALSE
        If InStr(LValid_Values, LChar) = 0 Then
            AlphaNumeric = False
        Exit Function
        End If

        'Increment counter
        LPos = LPos + 1

    Wend

    'Value is alphanumeric, return TRUE
    AlphaNumeric = True

End Function



The AlphaNumeric function will return TRUE if all of the values in the string are alphanumeric. Otherwise, it will return FALSE.

You can use the AlphaNumeric function as follows:

AlphaNumeric("6.49") would return TRUE
AlphaNumeric("^Tech on the Net ") would return FALSE
AlphaNumeric("hi~there") would return FALSE
________
Danish recipes
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group