Macro VBA code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I need to use the OnError method in a macro. Is there a way to do this?

What I'm trying to do in the macro is say: Run this query, but if there is
an error, do XXX .
 
error handler
---

Hi Mark,

below Access 2007, there is no error trapping for macros -- why not
convert your macro to code?

To convert a macro to VBA code,
select the macro in the Database Window,
then, from the menu --> Tools, Macro, Convert Macros To Visual Basic,
then click "Convert"

then Add an error handler to your code

ERROR HANDLER CODE:

put this at the top of your program, right after the procedure
declaration (skip a line first for better readability)

'~~~~~~~~~~~~~~~~~~~~~~
On Error GoTo Proc_Err

'~~~~~~~~~~~~~~~~~~~~~~
... then your statements
'~~~~~~~~~~~~~~~~~~~~~~

put this at the end of the program

'~~~~~~~~~~~~~~~~~~~~~~
Proc_Exit:
On Error Resume Next
'release object variables if any
Exit Function

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " ProcedureName"

'press F8 to step through code and debug
'remove next line after debugged
Stop: Resume
Resume Proc_Exit

'~~~~~~~~~~~~~~~~~~~~~~

where
ProcedureName is the name of your procedure so you can identify what
code the problem is in when you see the error


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
Very cool. Thanks Crystal!

strive4peace said:
error handler
---

Hi Mark,

below Access 2007, there is no error trapping for macros -- why not
convert your macro to code?

To convert a macro to VBA code,
select the macro in the Database Window,
then, from the menu --> Tools, Macro, Convert Macros To Visual Basic,
then click "Convert"

then Add an error handler to your code

ERROR HANDLER CODE:

put this at the top of your program, right after the procedure
declaration (skip a line first for better readability)

'~~~~~~~~~~~~~~~~~~~~~~
On Error GoTo Proc_Err

'~~~~~~~~~~~~~~~~~~~~~~
... then your statements
'~~~~~~~~~~~~~~~~~~~~~~

put this at the end of the program

'~~~~~~~~~~~~~~~~~~~~~~
Proc_Exit:
On Error Resume Next
'release object variables if any
Exit Function

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " ProcedureName"

'press F8 to step through code and debug
'remove next line after debugged
Stop: Resume
Resume Proc_Exit

'~~~~~~~~~~~~~~~~~~~~~~

where
ProcedureName is the name of your procedure so you can identify what
code the problem is in when you see the error


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
you're welcome, Mark ;) happy to help

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top