stop execution

  • Thread starter Thread starter al
  • Start date Start date
A

al

2nd post please help
In a form I put a commmandbutton with cancel and
default=true so when the program is running I could stop
the execution, but it does not work, I try click and
mouse-up subs. It only works after the code has finish
executing. What am I doing wrong? Can you give me an
example of how can I accomplish this task?
Thanks in advance
Al
..
 
Al,

Your code is executing, and during execution, you click on the Cancel
button. Your form is responding to events in the sequence in which they
occur.

Check out the DOEVENTS function.

Steve
 
What is your code doing that you want to cancel? Is it looping over a range
of values? It would help if you would post an example.
 
Create a form with two buttons and drop this into its code module.

Option Explicit
Private mCancel As Boolean

Private Sub CommandButton1_Click()
Dim n
Me.MousePointer = fmMousePointerHourGlass
For n = 1 To 10000
'long running process
Debug.Print n
DoEvents
If mCancel = True Then Exit For
Next n
mCancel = False
Me.MousePointer = fmMousePointerDefault
End Sub

Private Sub CommandButton2_Click()
mCancel = True
End Sub

Private Sub UserForm_Initialize()
mCancel = False
End Sub
 

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