Cancel button doesn't end macro 
Author Message
 Cancel button doesn't end macro

Why doesn't the "Cancel" button in an InputBox end the macro?  If it's not
supposed to, how do I end the macro if it's been pressed?  I've tried
checking the return value of vbCancel but now the macro is ended regardless
of the InpuBox response.  What am I doing wrong?

Here's the last piece of code that I tried.
    vResponse = InputBox(vMessage, vTitle, vDefault)
    If vbCancel = 2 Then
      MsgBox "Operation cancelled!"
      Exit Sub
    End If



Mon, 27 Dec 2004 03:05:36 GMT  
 Cancel button doesn't end macro
Hi Brian,

When I test your code, the routine exits the sub without a problem.
However, if you have a call stack and this routine is only one of the
routines in the call stack, then the Exit Sub statement will not end the
entire call stack. If this is what you're trying to accomplish, then use
"End"

HTH


Quote:
> Why doesn't the "Cancel" button in an InputBox end the macro?  If it's not
> supposed to, how do I end the macro if it's been pressed?  I've tried
> checking the return value of vbCancel but now the macro is ended
regardless
> of the InpuBox response.  What am I doing wrong?

> Here's the last piece of code that I tried.
>     vResponse = InputBox(vMessage, vTitle, vDefault)
>     If vbCancel = 2 Then
>       MsgBox "Operation cancelled!"
>       Exit Sub
>     End If



Mon, 27 Dec 2004 03:57:24 GMT  
 Cancel button doesn't end macro
Actually, my problem wasn't with it exiting (more on that to come), it was
how to identify that the InputBox "Cancel" button had been clicked and end
the sub on that click.  What was happening was that the sub continued to run
even after "Cancel" had been clicked.  I didn't run very long though.  I
discovered that the routine always got exited regardless of the InputBox
response because the value of vbCancel is always "2".  That made the If
statement always true so the sub always exited.  Reading further in the help
files I found that hitting "Cancel" returns a zero length string.  I was
able to check for that value in a Do While...Loop to solve the problem.

Brian


Quote:
> Hi Brian,

> When I test your code, the routine exits the sub without a problem.
> However, if you have a call stack and this routine is only one of the
> routines in the call stack, then the Exit Sub statement will not end the
> entire call stack. If this is what you're trying to accomplish, then use
> "End"

> HTH



> > Why doesn't the "Cancel" button in an InputBox end the macro?  If it's
not
> > supposed to, how do I end the macro if it's been pressed?  I've tried
> > checking the return value of vbCancel but now the macro is ended
> regardless
> > of the InpuBox response.  What am I doing wrong?

> > Here's the last piece of code that I tried.
> >     vResponse = InputBox(vMessage, vTitle, vDefault)
> >     If vbCancel = 2 Then
> >       MsgBox "Operation cancelled!"
> >       Exit Sub
> >     End If



Mon, 27 Dec 2004 21:20:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Command button doesn't execute macro when added via code

2. End doesn't end

3. END Statement doesn't end program!

4. Cancel doesn't work on async queries

5. CancelUpdate doesn't cancel all fields on a form

6. adCommand.Cancel doesn't seem to work with SELECT INTO query

7. Adodc.CancelUpdate doesn't realy cancel.

8. Cancel doesn't work on async queries

9. Please Help!: Cancel Doesn't Work

10. Setting application object to nothing doesn't end the process

11. End of File doesn't seem to work

12. ActiveX exe doesn't end...

 

 
Powered by phpBB® Forum Software