Disabling events when code is running

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,353
I have a userform with several togglebuttons. Each togglebutton has some code that runs using the ToggleButton1_MouseMove procedure - (the code involves activating a sheet and geting a list of values for entry into a textbox).

Once the 'Go' button is clicked, the main procedure runs to get data from an Access database, process it and write the result tio a new workbok. However, if the user moves the cursor over one of the togglebuttons while the main prcedure is running, an error occurs, as the ToggleButton1_MouseMove attempts to run. I want to arrange it so that this code is disabled when the main procedure is running. I guess I may be able to use Application.EnableEvents = False, but I wondor if there is a better way than this. If I set it to False, I need to make sure that it's set back to True at the end, and this has the problem that if there is an untrapped error, and the code errors out, then the user will be left in the Application.EnableEvents = False state, which I want to avoid.

Any ideas how to achieve this easily?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Yes but despite best efforts to predict all errors that might occur there is always the spectre of something entirely unpredictable or uncontrollable occuring, and it's just about impossible to catch everything. I really would like to just turn these events off. One way might be to hide the cursor, but I can't see how to do that. Another is to set the buttons to enabled = false but that's messy also as I have many buttons, some if which are only ever enabled for me (as the administrator), and some of which are enabled base on the user's selections. I want to avoid having to swithch everything off and back on again if possible.
 
Upvote 0
Soted! As it happens, the togglebutoons are all in a frame. I have simply set the frame to enabled=false at the start, then back to enabled = true at the end. In the event of an untrapped error, the form would unload anyway, and when reloaded, the frame' s default is enabled = true. Thanks for your suggestion anyway.
Regards
 
Upvote 0
Sorted! As it happens, the togglebutoons are all in a frame. I have simply set the frame to enabled=false at the start, then back to enabled = true at the end. In the event of an untrapped error, the form would unload anyway, and when reloaded, the frame' s default is enabled = true. Thanks for your suggestion anyway.
Regards
 
Upvote 0
Sorted! As it happens, the togglebutoons are all in a frame. I have simply set the frame to enabled=false at the start, then back to enabled = true at the end. In the event of an untrapped error, the form would unload anyway, and when reloaded, the frame' s default is enabled = true. Thanks for your suggestion anyway.
Regards
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top