468,101 Members | 1,399 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

How to cancel/stop code execution

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.

Thanks,
sphinney
Oct 24 '08 #1
4 26226
DonRayner
489 Expert 256MB
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
NeoPa
32,019 Expert Mod 16PB
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
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!

sphinney
Oct 27 '08 #4
NeoPa
32,019 Expert Mod 16PB
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.

Similar topics

7 posts views Thread by Jo | last post: by
1 post views Thread by Default | last post: by
5 posts views Thread by Adrian Enders | last post: by
1 post views Thread by Sabiyur | last post: by
4 posts views Thread by Ralphz | last post: by
3 posts views Thread by =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.