Creating Error catching in VBA (Access 2007)

Posted on 2011-05-03
Last Modified: 2012-05-11

I need to come up with a proper (best) way to catch error in my access 2007 application. I have created an error table and plan on insert error code and descriptions in the table instead of showing it as a message box. How should I go about this? Should I create one function that inserts the error into the error table, then from my other functions is where I call the error function?

My error table is

ErrorLogID autonumber
ErrNumber TEXT
ErrDescription TEXT
ErrDate DAte/Time
CallingProc (function) TEXT
ShowUser Yes/No
Parameters TEXT

Question by:lulubell-b
    LVL 11

    Expert Comment

    yes, create one function that inserts the error function into the error table.

    let it take in parameters
    ErrObject - error number and description
    CallingProc - the name of the function

    in the function (errfunc) the
    ErrDate will be Now()

    set it up in each of your functions to call errfunc on error, with the name of the function as the callingproc

    see example
    Function tester()
        On Error GoTo errjump
        errfunc Err, "tester"
        Resume Next
    End Function

    Open in new window

    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    <I have created an error table and plan on insert error code and descriptions in the table instead of showing it as a message box.>

    Be careful of this as error numbers and descriptions can change in different versions of Access for the same error...

    LVL 10

    Expert Comment

    Here are a few of my papers that you may find helpful:

    This paper was also published on MSDN:
    Error Handling and Debugging Tips and Techniques for Microsoft Access, VBA, and Visual Basic 6 (VB6)

    Pinpointing the Exact Line Where A Crash Occurs in VB6 or VBA

    It's a matter of creating a global error handler to document the error. The challenge you may face is that depending on the error, it's not always possible to write it to a table. We always write errors to a text file located in the user's folder to avoid any database problems that may be occurring.

    You'll also want to make sure your environment has the right error handling settings when your application starts. That's covered in the first paper. Hope this helps.  Good luck.
    LVL 38

    Accepted Solution

    Try this free error handler wizard:

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Many companies are making the switch from Microsoft to Google Apps ( Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now