Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trap Specific Error in Macro

Status
Not open for further replies.

tjherman

Programmer
Jun 19, 2006
68
US
We have some macros that run silently via scheduled tasks in the evenings. Occasionally, these macros will error in some way and we want to log these errors. I've found code that I can run that will append the error number and text to a table that we can view as a log. However, I don't know how to check for a specific error. For example, the error message for "can't append all the records in the append query" is error number 10510. But this "error" is not seen as an error in the macro (or even in vba). When I use the [MacroError].[Number] <> 0 in the condition column of my macro, it returns false and I single step through the macro and see that the "Error Number" is 0 even though it complains about not being able to append data. Is there a way to check for specific errors in a macro? What would be different about these errors that would show the "Error Number" as 0 even though it actually did show an error message?
 
Ms Access does not / cannot trap errors in MACROs. If you are calling procedure(s) in Modules "Macro", yoy can trap some (but certainly not all) errors. The generic processfor trapping (in Code) is ~~
On Error GoTo SomeLabel

{other code here}

SomeLabel:

Select Case Err

case xxx1
'Process specific Err (Err xxx1) here

case xxx2
'Process specific Err (Err xxx2) here

more errors here ... as desired
End Select



MichaelRed


 
Actually, you can trap for errors in Access 2007 -- it's new to this version. I.e., you can put [MacroError].[Number] <> 0 in the condition column and trap for specific error numbers. Then there is an additional Action available of "ClearMacroError" which clears the error number in case you're wanting to move forward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top