Stopping code execution

J

Joey

I have a form that connects to a remote database and creates several
recordsets. Depending on the state of the remote db, this code may take some
time to run. I would like the user to be able to cancel out and stop the code
by hitting the ESC button or clicking a button. The code isn't one giant loop
- so I need to be able to stop it no matter hwere in the procedure I am.
If anyone knows how I can do this, I would greatly appreciate any help!
Thanks!
 
R

Roger Carlson

Just thinking off the top here.

I would create a Global variable of Boolean datatype. Make the conditional
or looping statement include the truth of this variable in EVERY routine.
For instance:

While Not rs.EOF and MyBool =True
....

Include a DoEvents comment in every routine.

Add code to the button that sets the boolean variable to False. When the
button is clicked, execution should fall through each routine till the end.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
J

Joey

Thanks for the reply.
However, there isn't all that looping going on. I'd like to be able to stop
the code if the code isn't in a loop.
Do I need to use the timer event and check for the user hitting the ESC key?
I can do this, but how do I tell the code to stop running in the original
procedure?
 
J

Joey

Thanks for your patience, Roger.
I am opening recordsets and returning the records. For example:
---> rs.Open "SELECT PartNum FROM PUB.Part WHERE PartCode = 'STD' ORDER BY
PartNum", cn, adOpenStatic, adLockOptimistic <----
The remote db is in use by several people at the time I might make the
request, so it varies in how long it takes to run this. Sometimes it will
sit on this line for 5 minutes. Is there a way to hit the ESC key and just
stop the code no matter what line it's on?
 
Top