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

Cancel a running process

Status
Not open for further replies.

wkilgroe

MIS
Oct 2, 2002
10
0
0
US
I have a loop that runs through and updates excel sheets. The form that calls this process has a cancel button on it, but it is useless because the click events are ignored while the loop is running. Any ideas how I can make the cancel button work? Btw, I have already used DoEvents to set the focus back to the cancel button on the form.
 
Hi wkilgroe,

You say you are already using the DoEvents command but I have used this to get my cancel button to work properly while another process is being ran. I did something like the following:

While
cntLine = cntLine + 1

Do something.....

If cntLine = 10 Then
cntLine = 0
DoEvents
End If
Wend

With this your cancel button should work properly when clicked.

Regards,
gkprogrammer
 
One approach is use a global variable which is set to false. In the Click event, set the variable to True, and check the value of the variable inside the loop.

Dim NotCancel as Boolean

Sub WhichHasTheLoop

NotCancel = False
Do While <your condition> and (NotCancel = False)
<your loop code>
Do Events
Loop

End Sub

Sub CancelButton_Click

NotCancel = True

End Sub



Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks, I used a combination of these suggestions and its working now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top