By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

How to cancel/stop code execution

P: 69
Hi everyone. I'm creating an application inside Access 2007. The application will retrieve data from various locations on my company's network servers.

Depending on the time of day, alignment of the planets, other unfathomable mysteries sometimes my company's network is very, very slow.

I would like to provide the user of my application with a "Cancel" button on a form that will cancel/stop execution of the code (at whatever point it may be at) if the user clicks the button.

Is there some sort of DoCmd method or something else I can call to cancel/stop code execution in Access?

I could use the "CancelEvent" method. But to use this method, I must insert it at pre-determined points in the code, and then test to see if the user has selected the cancel button. It would work, but it's not as instantaneous as I wuld like. Plus, if execution hangs because of a slow network (which is the condition I'm most concerned about) if it doesn't happen to be a the proper spot in my code, the CancelEvents method wont be called.

I could also instruct the user to hit "Ctrl-Break" on the keyboard to stop execution, but that would produce a error dialog box which the user must learn to hit the "End" button. And besides, I don't know if users could REMEMBER the "Ctrl-Break" combination. :-)

Any thoughts or suggestions are greatly appreciated.

Oct 24 '08 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 489
You could use the on timer event from a hidden form to check the state of a public variable that you set with the cancel button and then have it do the cancel event when it detects the change.
Oct 24 '08 #2

Expert Mod 15k+
P: 31,492
Unfortunately, most code run in Access is synchronous.

A timer event could certainly be triggered, but even a "Stop" statement in there would, I'm pretty sure, be both unsafe and not give you the solution you want.

Remember, when queries are run from non-Access based data sources, they are also generally synchronous and they leave the Access VBA suspended, so you can't even check for the status of a variable.
Oct 25 '08 #3

P: 69
Looks like my best bet is to go with the CancelEvent method. It works well enough. I just thought there might be some other command/method that would work better.

Thanks for your time and thoughts DonRayner and NeoPa!

Oct 27 '08 #4

Expert Mod 15k+
P: 31,492
No worries :)

Just sorry we didn't have any more to add.
Oct 27 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.