Re: Cancel while in process
Use of the keyword DoEvents in your loop will allow execution of your 'Cancel' button.
David Paulson
Re: Cancel while in process
Small example of Davids suggestion. Start a new project. Add two command buttons. Paste this code into general declarations section. Run it. Click Command1 which starts a long loop.
Click command2 to stop it.
option Explicit
'
Dim blCancel as Boolean
'
private Sub Command1_Click()
'
LongLoopSub ' start a long loop
MsgBox "Long Loop ended"
'
End Sub
public Sub LongLoopSub()
'
Dim Something as string
blCancel = false
Do Until Something = "Hello there"
'
DoEvents
If blCancel then Exit Sub
'
Loop
'
End Sub
private Sub Command2_Click()
'
blCancel = true
'
End Sub
John G