Below is a slightly more veratile function which handles both upper and lower
case alphabetical character as an input variable.
'---------------------------------------------------------------------------------------
' Procedure : ConLtrToNo
' Author : CARDA Consultants Inc.
' Website :
http://www.cardaconsultants.com
' Purpose : Convert Alphabetical characters into their numeric values
' a=1, b=2, c=3, ... and/or A=1, B=2, C=3, ...
' Copyright : The following may be altered and reused as you wish so long as
the
' copyright notice is left unchanged (including Author, Website
and
' Copyright). It may not be sold/resold or reposted on other
sites (links
' back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sLetter : The character to convert into a numerical value
'
' Usage Example:
' ~~~~~~~~~~~~~~~~
' ConLtrToNo("A")
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
'
**************************************************************************************
' 1 2010-Feb-13 Initial Releas
'---------------------------------------------------------------------------------------
Function ConLtrToNo(sLetter As String) As Integer
Dim iChrVal As Integer
On Error GoTo Error_Handler
iChrVal = Asc(sLetter)
Select Case iChrVal
Case 65 To 90 'Values A through Z
ConLtrToNo = iChrVal - 64
Case 97 To 122 'Values a through z
ConLtrToNo = iChrVal - 96
Case Else
ConLtrToNo = 0
End Select
Error_Handler_Exit:
On Error Resume Next
Exit Function
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: ConLtrToNo" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Function
--
Hope this helps,
Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples:
http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.