I have a procedure that steps through a large recordset and updates a progress bar everytime a move next is performed.
What I want to do is, based on the click of a cancel button I want to be able to exit out of this loop at any time.
Any ideas?????
Printable View
I have a procedure that steps through a large recordset and updates a progress bar everytime a move next is performed.
What I want to do is, based on the click of a cancel button I want to be able to exit out of this loop at any time.
Any ideas?????
Exit Do ' exits a Do while Loop
Create a boolean variable with either form-level or global scope depending on your needs, and set it to True when the user clicks cancel. Inside your Do loop put If myBoolean = True Then Exit Do. You will also need to add a DoEvents inside the loop.
One way to do this is to use a public boolean as an additional condition on your recordset loop. If your cancel button is pressed this var gets set to false. You'd want to have a DoEvents inside your loop to make sure that the cancel button actually happens when the loop is running.
All you'd need in your cmdCancel_Click event is code to change blnDoLoop to false.Code:blnDoLoop = True ' This var should be declared as Public.
Do While Not rstYourRecordset.EOF And blnDoLoop
'
' Whatever...
'
DoEvents
rstYourRecordset.MoveNext
Loop
Paul