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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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).
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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