The IsAlphanumeric Function
Public Function IsAlphanumeric(intKeyAscii As Integer, _
Optional blnEscTabBackReturn = True) _
As Boolean
'Copyright (c) Brendan Reynolds/Timarco Ltd, 1999.
'All rights reserved.
'e-mail [email protected]
'This function returns True if the intKeyAscii argument
'is the ASCII code for an alphanumeric key ('a' to 'z',
'upper or lower case, or '0' to '9'). By default, the
'function will also return True if intKeyAscii is the
'ASCII code for the Escape, Tab, Backspace or Return
'key. This behaviour can be over-ridden by passing a
'value of False for the optional argument
'blnEscTabBackReturn.
'Use (from the KeyPress event of a control or form):
'blnAlphaNum = IsNumeric(KeyAscii)
'Alternatively:
'If IsNumeric(KeyAscii, False) Then
' do something
'Else
' do something else
'End If
On Error GoTo Err_Routine
Dim lngErrNum As Long
Select Case intKeyAscii
Case Asc("A") To Asc("Z")
IsAlphanumeric = True
Case Asc("a") To Asc("z")
IsAlphanumeric = True
Case Asc("0") To Asc("9")
IsAlphanumeric = True
Case vbKeyEscape, vbKeyTab, vbKeyBack, vbKeyReturn
If blnEscTabBackReturn Then
IsAlphanumeric = True
Else
IsAlphanumeric = False
End If
Case Else
IsAlphanumeric = False
End Select
Exit_Routine:
Exit Function
Err_Routine:
lngErrNum = Err.Number
Select Case Err
'
Case Else
Err.Raise lngErrNum
Resume Exit_Routine
End Select
End Function
Download this function in plain text format, ready for import into your own Microsoft Access 97 or Microsoft Access 2000 application, here. |