ISALPHA or ISNUMERIC functions ?

  • Thread starter Thread starter CaptainWillard
  • Start date Start date
C

CaptainWillard

I'm trying to find the Access versions of the functions to
determine if a character in a string is A-Z or 0-9. I can't seem to
locate the functions in the help file. In a perfect world., Access
would have a function like ISTEMPLATE, which would work as follows:
ISTEMPLATE("A999A99", strField1) which would return T for
strField1="D102X34" and F for strField1=""D1023X4". Is there any
function like that, or any functions for matching strings by character
type? Thanks in advance for any help.
 
Please do not post duplicate threads.

If you want your post to appear in more than one group, enter all the group
names in the "Newsgroups:" field when submitting your post. This will post
a copy to each newsgroup. If anyone responds in one newsgroup, their
resolution will appear in all copies of your message. This prevents people
from spending time answering your question only to find that it was answered
by someone else in another newsgroup.
 
There are a few things that will help, but this seems closest to what you
want. Also have a look at IsNumeric, IsDate, IsMissing. .and so on


Built-in pattern matching provides a versatile tool for making string
comparisons. The following table shows the wildcard characters you can use
with the Like operator and the number of digits or strings they match.

Character(s) in pattern Matches in expression
? Any single character
* Zero or more characters
# Any single digit (09)
[charlist] Any single character in charlist
[!charlist] Any single character not in charlist
 
I'm trying to find the Access versions of the functions to
determine if a character in a string is A-Z or 0-9. I can't seem to
locate the functions in the help file. In a perfect world., Access
would have a function like ISTEMPLATE, which would work as follows:
ISTEMPLATE("A999A99", strField1) which would return T for
strField1="D102X34" and F for strField1=""D1023X4". Is there any
function like that, or any functions for matching strings by character
type? Thanks in advance for any help.

Hi Willard,

This may be close to what you want.

Public Function fIsTemplate(pTemplate As Variant, pString As Variant) As
Boolean
On Error GoTo Err_fIsTemplate
Dim lngLenTemp As Long, lngLenStr As Long, i As Long

lngLenTemp = Len(Trim(pTemplate & ""))
lngLenStr = Len(Trim(pString & ""))

If (lngLenTemp = 0) Or (lngLenStr = 0) Or (lngLenTemp <> lngLenStr) Then
fIsTemplate = False
Exit Function
Else
'continue
End If

fIsTemplate = True
For i = 1 To lngLenTemp
Select Case Mid(pTemplate, i, 1)
Case "A" 'is char alpha?
Select Case Asc(Mid(pString, i, 1))
Case 65 To 90, 97 To 122 'A-Z, a-z
'continue
Case Else
fIsTemplate = False
Exit Function
End Select
Case "9" 'is char numeric?
Select Case Asc(Mid(pString, i, 1))
Case 48 To 57 '0-9
'continue
Case Else
fIsTemplate = False
Exit Function
End Select

Case Else
fIsTemplate = False
Exit Function
End Select
Next i

Exit_fIsTemplate:
Exit Function

Err_fIsTemplate:
MsgBox Err.Description
Resume Exit_fIsTemplate

End Function


quick tests in Immediate window:

mystring="D1023X4"
mytemplate="A999A99"
?fIsTemplate(mytemplate,mystring)
False
mystring="D102X34"
?fIsTemplate(mytemplate,mystring)
True
mystring=""
?fIsTemplate(mytemplate,mystring)
False
mystring="D103X3"
?fIsTemplate(mytemplate,mystring)
False
mytemplate=""
?fIsTemplate(mytemplate,mystring)
False
mytemplate="A99AAA"
?fIsTemplate(mytemplate,mystring)
False


This probably is one of those cases
where giving a poster what they want
is not the best advice, but...

good luck,

gary
 
Back
Top