The following is a simple way to insert basic error trapping into any MSAccess
Function or Sub.

I created a macro to run the code, and attached the macro to a button on the Module toolbar - just press the button (even if your code is already written) and the error trapping is created. You will have to cut and paste your code back into the proper location.

This is based on something I found in the Access Forum, using Windows Recorder. Since migrating to NT 3.5, Recorder is not that reliable, hence this function.

To use this, simply paste the code below into a Global Module, create a macro to run the code, and add the macro as a button on the Module toolbar.

Whenever you create a new procedure (or want to add basic error trapping to an existing one), open the procedure, and push the button.

Hope this is of some use.

Send comments/suggestions to:

Tom C. Tucker
75357,221

***********Basic Error Trapping***************

Function ErrorCode ()
On Error GoTo Err_ErrorCode

    SendKeys "^{HOME}"
    SendKeys "^{RIGHT}"
    SendKeys "^+{RIGHT}", True
    DoCmd DoMenuItem 5, A_EDITMENU, 2, , A_MENU_VER20
    SendKeys "{END}{ENTER}"
    SendKeys "'On Error GoTo Err_", True
    DoEvents
    DoCmd DoMenuItem 5, A_EDITMENU, 3, , A_MENU_VER20
    SendKeys "{ENTER 3}"
    SendKeys "'Exit_"
    DoEvents
    DoCmd DoMenuItem 5, A_EDITMENU, 3, , A_MENU_VER20
    SendKeys ":{ENTER}{TAB}Exit Function"
    SendKeys "{ENTER 2}"
    SendKeys "'Err_"
    DoEvents
    DoCmd DoMenuItem 5, A_EDITMENU, 3, , A_MENU_VER20
    SendKeys ":{ENTER}{TAB}"
    SendKeys "MsgBox ""Encountered error:  "" & Str${(}Err{)} & Chr{(}10{)} & Error$, ,  """"{LEFT}", True
    DoEvents
    DoCmd DoMenuItem 5, A_EDITMENU, 3, , A_MENU_VER20
    DoEvents
    SendKeys " "
    SendKeys "Error"
    SendKeys "{END}{ENTER}"
    SendKeys "'Resume Exit_"
    DoEvents
    DoCmd DoMenuItem 5, A_EDITMENU, 3, , A_MENU_VER20
    SendKeys "^{HOME}{DOWN}{DEL}{DOWN 3}{DEL}{DOWN 3}{DEL}"
    SendKeys "{DOWN 2}{RIGHT 4}{DEL}{UP 6}"

Exit_ErrorCode:
    Exit Function

Err_ErrorCode:
    MsgBox "Encountered error:  " & Str$(Err) & Chr(10) & Error$, , "ErrorCode Error"
    Resume Exit_ErrorCode
End Function
