• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to Exit a UserForm without clickng 'X'

Debraj

Excel Ninja
Hi Excelian,


I am trying to get code like Me.Close..


Actually I have a code to get unique value in ComboBox at UserForm_Initialize event. But when form.hide and then form.show, it was not fired.


I have already move it to Userform_activate section, but just for knowledge.., what event trigger after UserForm_QueryClose
event.
 
Hi, Debraj Roy!

For quitting an user form without clicking the top right red "X" you can assign True to Cancel property of a command button, or to True to its Default property, which are seldom used for quit button or enter button.

Usually the form has a default action to be performed (Default = True for that command button) and a command button for exiting (Cancel = True): so if you press Enter its interpreted as clicking on button with Default = True, and if you press Escape its interpreted as clicking on button with Cancel = True. Then can be both the same, too.

Regards!
 
Thanks Sir,

I always use this two property in my forms.

Which CommandButton need to fire at ENTER (ir-respective of current focus) I use Default = TRUE

and Which CommandButton need to fire at ESC(ir-respective of current focus) I use Cancel= TRUE



But I never know that these two property are, indirectly property of Form..

Thanks JB-007..
 
Hi, Debraj Roy!


Maybe I didn't expressed myself properly. What I meant to say it was that at least you should have two buttons (Go and Back), one for performing any action and other for closing form. So you assign True to Default property of Go and True to Cancel property of Back.


Assume you have this code:

Go_Click(): MsgBox "hi"

Back_Click(): Unload Me


Then pressing Enter you'll get a "hi" and pressing Escape form will be closed.


I shouldn't say that they're indirectly form properties, even if only one control in form might have one of them set to true. In such way they're form properties, but they really trigger control (command button) events, not form events, so in this way, they aren't.


Regards!
 
Back
Top