How to Stop a Macro if a 'Call' macro was used

C

Corey

Is ther a way to Cancel a CommandButton on a form via a Module Sub Routine ?

I can have :
Userform1.CommandButon2.Cancel
but it does not STOP the macro from running that called the other macro in
the module, but returns an error.

Is ther a way to STOP/CANCEL a CommandButton continuing from a Module code?

Corey....
 
S

Susan

you'd have to code in the condition..........

if <condition> then
exit sub
end if

when it exits then it would go back to the first macro that called
it. once it's in the middle of running the only way to break out of
it is Ctrl+Break.
hth
:)
susan
 
C

Corey

I do nto know how i can place an IF condition though.

I use a :
Sub CommandButton2_Click()
'code blah blah blah
........
Call Macro1
end Sub

How would i place a condition in the Call Macro1 to Exit the CommandButton
Sub IF the Macro1 Changes something?

Corey....

you'd have to code in the condition..........

if <condition> then
exit sub
end if

when it exits then it would go back to the first macro that called
it. once it's in the middle of running the only way to break out of
it is Ctrl+Break.
hth
:)
susan
 
S

Susan

you'd need some sort of a boolean value, then......

call Macro1
'then when it comes back to
'commandbutton2, check your
'boolean
if myboolean = true then
exit sub
end if

and in the macro1 sub, you'll need to set the boolean before you exit
the macro1 sub.........

if <condition> then
myboolean=true
exit sub
'goes back to commandbutton2 here
end if

make sure your myboolean variable is a public variable, though, so it
will carry over between the subs.
hth
susan
 
C

Corey

Thank you will give that a try.
you'd need some sort of a boolean value, then......

call Macro1
'then when it comes back to
'commandbutton2, check your
'boolean
if myboolean = true then
exit sub
end if

and in the macro1 sub, you'll need to set the boolean before you exit
the macro1 sub.........

if <condition> then
myboolean=true
exit sub
'goes back to commandbutton2 here
end if

make sure your myboolean variable is a public variable, though, so it
will carry over between the subs.
hth
susan
 

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

Top