Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Southern California

    Want function to get current function name

    I am developing an all-purpose error handler. As I see it, the "ideal" function would look like this:

    Public Function Foo()
    On Error GoTo er
    'Code goes here...
    ex: 'Cleanup code, closing open objects, etc.
    Exit Function

    erf 'An error handling function, which writes this function's name
    'and error stats to a table, then returns here.
    MsgBox Err.Description 'Allows stepping through code in this function.
    Resume ex 'Gets cleanup code.
    End Function

    The only issue I'm having is having to pass the current function name in to my error handler. Does anyone know a way to get this systematically?

  2. #2
    jase_kross is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2009
    Orange, CA (USA)
    There is a chapter on Error Handling in Expert Access 2007 Programming (Wrox Press) that touches on what you are trying to accomplish. The authors mention that they want to build an error handling framework where they can log a procedure's name in the event of an error. The authors state -
    In addition, as you’ve already seen, there is no way to dynamically determine the current routine that is currently running when an error occurs. To solve ....... create a class module called ErrorHandler.
    The code the authors provide can be easily adapted to run in a mdb file (hence Access 2003). Code for the chapter with the error handling modules is available at -

    Since it appears that you are using Access 2003 and may not have access to Access 2007 for conversion you may want to ask somebody to convert the file or send you the modules as text files (I am willing to help you as well, pm me). If you have access to a bookstore with the book you may want to look through it as well to see what the authors are trying to express as well as to get an understanding of their approach.

  3. #3
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Here is a sample method of using the On Error

       Dim DisplayMessage As String
       DisplayMessage = Nz(Choose(Application.CurrentObjectType, "Query", "Form", "Report", "Macro", "Module"), "Host")
       DisplayMessage = DisplayMessage & vbTab & ": " & Application.CurrentObjectName & vbNewLine
       DisplayMessage = DisplayMessage & "Event" & vbTab & ": OpenDatePicker" & vbNewLine
       DisplayMessage = DisplayMessage & "Error" & vbTab & ": " & Err & vbNewLine
       DisplayMessage = DisplayMessage & "Text" & vbTab & ": " & Error$ & vbNewLine
       DisplayMessage = DisplayMessage & vbNewLine & "If this error persists please note down these details together with what you were trying to do and call for technical assistance."
       MsgBox DisplayMessage, vbCritical + vbOKOnly, "An error has occured in "
       OpenDatePicker = False
       Resume OpenDatePicker_Exit

Please reply to this thread with any new information or opinions.

Similar Threads

  1. function key
    By marianne in forum Access
    Replies: 5
    Last Post: 05-14-2009, 01:26 AM
  2. Avg Function
    By hiker8117 in forum Access
    Replies: 3
    Last Post: 04-23-2009, 11:14 PM
  3. Is there a function to do this....
    By Nowherefast in forum Access
    Replies: 2
    Last Post: 12-31-2008, 08:08 AM
  4. DateDiff function
    By Scott R in forum Reports
    Replies: 5
    Last Post: 12-03-2008, 07:32 AM
  5. Need Help for Dlookup function
    By wasim_sono in forum Programming
    Replies: 5
    Last Post: 01-04-2006, 08:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Other Forums: Microsoft Office Forums - Senior Forums