X to close UserForm problem (SOLVED)

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
I have a procedure that calls a UserForm. If a user clicks the X button to close the UserForm, I need the procedure to be terminated. How do I code that?

_________________
Pass on what you have learned. Support this great website by clicking on the sponsor's ads!.
This message was edited by phantom1975 on 2002-08-30 10:07
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Jay Petrulis

MrExcel MVP
Joined
Mar 17, 2002
Messages
2,040
Hi,

When your UserForm is dismissed, you usually have a variable in some variable(s) which is (are) used in the rest of the procedure. The cancel button should set that variable to False (or Empty or blank or "" or "False" depending on the data types).

Capture that return value and test it. If it is false, then exit the procedure, else continue.

If you don't have your form set up that way, create a variable that just tests how the userform was dismissed (e.g. set it to True when your form buttons are clicked, and default it to false).
 

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
That's usually what I will do, however, the variables that are set up within the UserForm are Public variables and I do not want to clear out their values to set up an IF statement. Is there a code that specifies if the user clicks that particular button?
 

Jay Petrulis

MrExcel MVP
Joined
Mar 17, 2002
Messages
2,040
Hi,

You can either add a new variable that will only be set to TRUE or such only if the correct dismissal buttons are used, or you can use .QueryClose event to see if the user clicks the 'X' to dismiss.

The QueryClose event has a number of settings that you can test.
 

Forum statistics

Threads
1,144,274
Messages
5,723,447
Members
422,497
Latest member
dougy99

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
Top