PC Review


Reply
Thread Tools Rate Thread

Cancel an exit

 
 
ranswrt
Guest
Posts: n/a
 
      30th Jul 2008
How do I give an option to stop an exit from a userform when the 'X' is used
on them form?
Thanks
 
Reply With Quote
 
 
 
 
Corey
Guest
Posts: n/a
 
      30th Jul 2008
Personally IMHO disable the Button, so the ONLY way to Close the form is via
a CommandButton instead.

SEE: http://www.vbforums.com/showthread.php?t=363931

Corey....

"ranswrt" <(E-Mail Removed)> wrote in message
news:794C9CE2-E21E-46A9-803B-(E-Mail Removed)...
> How do I give an option to stop an exit from a userform when the 'X' is
> used
> on them form?
> Thanks



 
Reply With Quote
 
ranswrt
Guest
Posts: n/a
 
      30th Jul 2008
Thanks I'll give that a try.

"Corey" wrote:

> Personally IMHO disable the Button, so the ONLY way to Close the form is via
> a CommandButton instead.
>
> SEE: http://www.vbforums.com/showthread.php?t=363931
>
> Corey....
>
> "ranswrt" <(E-Mail Removed)> wrote in message
> news:794C9CE2-E21E-46A9-803B-(E-Mail Removed)...
> > How do I give an option to stop an exit from a userform when the 'X' is
> > used
> > on them form?
> > Thanks

>
>
>

 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      30th Jul 2008
If you include this in the userform's module it will achieve your goal:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Cancel = True
End Sub


--
Jim
"ranswrt" <(E-Mail Removed)> wrote in message
news:794C9CE2-E21E-46A9-803B-(E-Mail Removed)...
| How do I give an option to stop an exit from a userform when the 'X' is
used
| on them form?
| Thanks


 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      30th Jul 2008
You would use the UserForm's QueryClose event to control that. There are
lots of ways to structure the code you place there; here is a very simple
setup you can use as a guide...

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
If vbYes = MsgBox("Are you sure you want to close me?", vbYesNo) Then
' Perform any code cleanup here before letting the program close
Cancel = False
Else
Cancel = True
End If
End If
End Sub

Look up the QueryClose Event in the help files to see what else you can
check for with the CloseMode parameter. Note that while I put the
Cancel=False statement in, it is not technically needed as that is the
default for the Cancel parameter if not specifically specified (I think
including it makes the code "more complete").

Rick


"ranswrt" <(E-Mail Removed)> wrote in message
news:794C9CE2-E21E-46A9-803B-(E-Mail Removed)...
> How do I give an option to stop an exit from a userform when the 'X' is
> used
> on them form?
> Thanks


 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      30th Jul 2008
Personally, I wouldn't disable the button as the code to handle the user
pressing the "X" is too easy to implement (see my direct posting to the OP
in this thread) and leaving that option available to the user will make your
interface feel more natural to him/her. You can, of course, provide an
Exit/Close/Quit type button as well, I just would not go out of my way to
disable the "X" in favor of it.

Rick


"Corey" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Personally IMHO disable the Button, so the ONLY way to Close the form is
> via a CommandButton instead.
>
> SEE: http://www.vbforums.com/showthread.php?t=363931
>
> Corey....
>
> "ranswrt" <(E-Mail Removed)> wrote in message
> news:794C9CE2-E21E-46A9-803B-(E-Mail Removed)...
>> How do I give an option to stop an exit from a userform when the 'X' is
>> used
>> on them form?
>> Thanks

>
>


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      30th Jul 2008
As a user, I like to click on the X button to close any dialog.

If you have special code built into your "Cancel" button, why not just call that
same code.

Option Explicit
Private Sub CommandButton1_Click()
MsgBox "Ok was clicked"
End Sub
Private Sub CommandButton2_Click()
MsgBox "Cancel was clicked"
Unload Me
End Sub
Private Sub UserForm_Initialize()
With Me.CommandButton1
.Caption = "Ok"
.Default = True
End With
With Me.CommandButton2
.Caption = "Cancel"
.Cancel = True
End With
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call CommandButton2_Click
End If
End Sub


ranswrt wrote:
>
> How do I give an option to stop an exit from a userform when the 'X' is used
> on them form?
> Thanks


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cancel/Exit Sub Howard Microsoft Excel Misc 3 16th Dec 2008 09:53 PM
cancel exit maple via AccessMonster.com Microsoft Access Form Coding 1 24th Aug 2006 01:44 PM
Cancel an application exit from VBA? helmekki Microsoft Excel Programming 3 28th Oct 2005 03:31 AM
Outlook exit and cancel semut Microsoft Outlook VBA Programming 3 26th Jul 2005 02:08 PM
Cancel Exit From Module Bryan Hughes Microsoft Access Form Coding 0 16th Sep 2003 08:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 AM.