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