UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> VbConstant    


Synopsis

Refer to constants that are defined in VBA in Access query criteria.

As presented here, the function returns results corresponding to the constants vbSunday ... vbSaturday. The function can be extended by including additional case statements.

CODE
' VbConstant
' http://www.utteraccess.com/wiki/VbConstant
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2011-02-19                    
'
Public Function vbConstant(rstrConstant As String) As Variant
' Procedure: vbConstant
' Description: Return the value of a defined Visual Basic constant
'--

   Const cstrProcedure = "vbConstant"
   Const clngUnknownErrCode = vbObjectError + 65536
   Const cstrUnknownErrMsg = "Unknown Constant Identifer"

   Dim strErrMsg As String
   Dim varResult As Variant

   On Error GoTo HandleError

   Select Case rstrConstant

   Case "vbSunday"
       varResult = vbSunday
   Case "vbMonday"
       varResult = vbMonday
   Case "vbTuesday"
       varResult = vbTuesday
   Case "vbWednesday"
       varResult = vbWednesday
   Case "vbThursday"
       varResult = vbThursday
   Case "vbFriday"
       varResult = vbFriday
   Case "vbSaturday"
       varResult = vbSaturday
   Case Else
       Err.Raise clngUnknownErrCode, cstrProcedure, cstrUnknownErrMsg & " " & rstrConstant
       
   End Select

   vbConstant = varResult
   
HandleExit:

   Exit Function

HandleError:

   Select Case Err
   
   Case clngUnknownErrCode
       strErrMsg = "Error " & Err.Number & " in Procedure " & cstrProcedure & " " & Err.Description
       MsgBox strErrMsg, vbCritical + vbOKOnly, "Constant Identifier Error"
   Case Else
       'insert general error handler here
       'ErrorHandle Err, Erl(), cstrModule & "." & cstrProcedure
       'Resume HandleExit
   End Select
End Function

Creative Commons License
VbConstant by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 3,832 times.  This page was last modified 09:07, 6 April 2011 by Jack Leach. Contributions by Glenn Lloyd  Disclaimers