|
-
August 14th, 2001, 10:40 AM
#1
Cancel while in process
I have a section of code that retrieves a number (variable amount) of records from a database. Upon retrieval, the code loops through the records one by one and performs a number of functions with these records. This can sometimes take too long for an impatient user and they want to cancel out of the operation. What is the best to allow the user to press a cancel button left on the screen? Usually, when I am executing code, there is no interaction by the user allowed... Any suggestions would be greatly appreciated!!
Thank you.
-
August 14th, 2001, 01:35 PM
#2
Re: Cancel while in process
Use of the keyword DoEvents in your loop will allow execution of your 'Cancel' button.
David Paulson
-
August 14th, 2001, 08:29 PM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|