Exit Userform and run code

davidam

Active Member
Joined
May 28, 2010
Messages
497
Office Version
  1. 2021
Platform
  1. Windows
Hello All,
I tried wanted to have some code that executed when I clicked the Red X on a user form...I used CanceQuery for this. I have other buttons on the form and each of those buttons has the line "Unload Userform ". I am pretty sure that what is happening ,however, is that the CancelQuery code is running when the Unload Userform command is encountered. Is there a way to install some code that will ONLY run if/when I use the red X?
Thank you
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Set a toggle in the cancel button that is recognized by the terminate event.

That way when the cancel button triggers, it will not trigger the code. Only unloading the userform with the red X or using some other method will trigger it.
 
Upvote 0
Yes that is probably the way to go...I have found toggles to be troublesome in the past because you always have to make sure they get re-set...this is a good situation though, because I can wrap the button unload commands with a toggle trip and re-set and make the query/close conditional...Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,484
Members
452,917
Latest member
MrsMSalt

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