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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit Macro

Status
Not open for further replies.

JoeReed

Programmer
Joined
Nov 3, 2003
Messages
10
Location
US
I have a macro that calls several VBA modules along with a couple of queries. If I have an error in the first module I want to exit out of the Calling Macro.

Currently if I have an error in the first module I exit that module but then it goes into the second module and so on.

Any help would be appreciated.
 
Hi,

You could try creating a function in VBA that will run the same bits of code and queries and then you can handle errors from that function.

Dean.
 
how about something like this.

add these step to the macro:

Condition Action Comment
---------------------------------------------------------
RunCode runs function1()
errors()<>0 StopMacro stops current macro from running

then add the code below to a module:

Option Compare Database
Public errorcode As Integer
Public test As Integer

Function function1() As String
On Error GoTo errs
' setting test to Null generates an error.
' set test = 1 and all functions will execute.
'test = Null
test = InputBox(&quot;enter a number. leave blank to produce an error and stop macro.&quot;)
MsgBox &quot;function 1&quot;
errs:
errorcode = Err.Number
End Function

Function function2() As String
On Error GoTo errs
MsgBox &quot;function 2&quot;
errs:
errorcode = Err.Number
End Function

Function function3() As String
On Error GoTo errs
MsgBox &quot;function 3&quot;
errs:
errorcode = Err.Number
End Function

Public Function errors() As String
errors = errorcode
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top