Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Oct 2001
    Location
    Upper NY State, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Handler-Access 2000 VBE (Access 2000)

    I heard there might be a way to edit the VBEditor to assist in automatically adding error handling to my procedures. What I have been doing is creating a new procedure, copying and pasting the following error handling shell into the procedure and using find/replace to substitute the procedure name into the "xx". I then do an uncomment block and make any minor edits. You can't customize the VBE editor menus like those in Access. Is there some way to add a cut and paste or insert of the text below into a module and (this is a wish) replace the xx with the procedure name? I have played with code for using the clipboard, but have not had any success. Here's an example of some boilerplate error handling code:

    'On Error GoTo xx_err
    '
    'xx_Exit:
    '' set db=Nothing
    ' ' Set rst = Nothing
    ' Exit Sub
    '
    'xx_err:
    'If err.number = zz then
    '' DoThis
    ' 'Resume next
    ''Else
    ' GlobalErrorHandler Err.Number, Err.Description, VBE.SelectedVBComponent.Name, "xx", Err.Source
    ''End if
    ' GoTo xx_Exit

    Just seems kind of funny you can get Access to automatically add error handling to to a converted macro, but not a new procedure? Looks like the tools are there but not available.

    Thank you,

    Dave

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Handler-Access 2000 VBE (Access 2000)

    I don't know about code but I use <A target="_blank" HREF=http://www.fmsinc.com/products/CodeTools/index.html>Total Visual Code Tools</A> from FMS to do this and much more
    Francois

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Error Handler-Access 2000 VBE (Access 2000)

    You might want to take a look at the <A target="_blank" HREF=http://www.mvps.org/access/modules/mdl0040.htm>CodeWriter 2.0</A> download on The Access Web. It does at least some of what you're wanting to do.

    By the way, in Access 2000, you can use the same label names in multiple procedures. I personally use Proc_exit and Proc_err for the names of my error handler and exit labels in all my routines.
    Charlotte

  4. #4
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Error Handler-Access 2000 VBE (Access 2000)

    An easy way to do this is to create your generic error handling routine(s) and save them as simple text files in Notepad. Save these files in your default Access folder. When adding a new procedure in the VB Editor, use the Insert>File.... menu command to insert your error handling text file between the Sub/End Sub statements. The Insert>File command opens in the default Access folder, with text files (*.txt) as the default file type. Example:

    <pre>Private Sub ErrHandler()
    On Error GoTo Err_Handler

    Exit_Sub:
    Exit Sub

    Err_Handler:
    Dim ErrMsg As String
    If Err = ErrNo Then 'Describe error
    ErrMsg = "Describe error and corrective action"
    Beep
    MsgBox ErrMsg, vbExclamation, "ERROR MESSAGE"
    Else
    ErrMsg = "Error No " & Err.Number & ": " & Err.Description
    Beep
    MsgBox ErrMsg, vbExclamation, "GENERIC ERROR MESSAGE"
    End If

    Resume Exit_Sub

    End Sub</pre>

    I use generic labels for the Exit Sub and error handling statements. For function procedures I use a modified version of the above. Another option: There's a VBA Error Handler Add-In that functions in a similar manner, by inserting an error handling template into your procedure. However, I think this add-in (and other useful VBE add-ins) is available only if you have Office Developer Edition installed.

    HTH

  5. #5
    Lounger
    Join Date
    Oct 2001
    Location
    Upper NY State, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Handler-Access 2000 VBE (Access 2000)

    I have attempted to get some of the quality addins described but my company will not purchase them even if the time saved will pay for them over and over. I have considered adding some of the third party addins to my Christmas list for next year at home and let my work product benefit from that. For now, I will work with MarkD's idea. It's too bad Microsoft has the builders in A2000 but only lets you use them for some tasks. CRouseau has a nice code library addin which was designed for A97 but does not work in A2000.

    I have not checked the CodeWriter2.0 yet but will when I get my head above water!

    Once again, Thank you ALL for your advice!

    Dave

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Error Handler-Access 2000 VBE (Access 2000)

    As an aside, Access 97 add-ins don't work in Access 2000 because the USysRegInfo table requires a different number of records in 2000. Also, add-ins like that work in the UI, not in the VBE where you might need them. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •