Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default userform titlebar and closing form

I would like to prevent the user from closing a userform by clicking the 'X'
on the right side of the titlebar. I need to force closure by using a
command button, and running an exit procedure. Is there a property setting
that will prevent this / or run the exit procedure when the 'X' is clicked?

D.S.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default userform titlebar and closing form

DS,

You can use the QueryClose event procedure to catch the form's
closing via the 'X' button.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"D.S." wrote in message
...
I would like to prevent the user from closing a userform by

clicking the 'X'
on the right side of the titlebar. I need to force closure by

using a
command button, and running an exit procedure. Is there a

property setting
that will prevent this / or run the exit procedure when the 'X'

is clicked?

D.S.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default userform titlebar and closing form

Use the form's QueryClose event. This has 2 arguments, Cancel and CloseMode.
CloseMode tells you where the close originates from.

vbFormControlMenu 0 The user has chosen the Close command from the
Control menu on the UserForm.
vbFormCode 1 The Unload statement is invoked from code.
vbAppWindows 2 The current Windows operating environment session is
ending.
vbAppTaskManager 3 The Windows Task Manager is closing the
application.


You can test this, and if it's from an unload statement, close else cancel

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Cancel = CloseMode < vbFormCode And CloseMode < vbAppWindows
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"D.S." wrote in message
...
I would like to prevent the user from closing a userform by clicking the

'X'
on the right side of the titlebar. I need to force closure by using a
command button, and running an exit procedure. Is there a property

setting
that will prevent this / or run the exit procedure when the 'X' is

clicked?

D.S.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default userform titlebar and closing form

Great, that will work. I found another method, but it's more complicated
that I require for this project.

Thanks,
D.S.


"Chip Pearson" wrote in message
...
DS,

You can use the QueryClose event procedure to catch the form's
closing via the 'X' button.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"D.S." wrote in message
...
I would like to prevent the user from closing a userform by

clicking the 'X'
on the right side of the titlebar. I need to force closure by

using a
command button, and running an exit procedure. Is there a

property setting
that will prevent this / or run the exit procedure when the 'X'

is clicked?

D.S.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default userform titlebar and closing form

I would like to run my "cmdExit" procedure here, if the user clicks the
close button, but I haven't had any luck. I get a syntax error. Can a
procedure be ran from here?


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing with the Close box in the title bar.
If CloseMode < 1 Then Cancel = 1
' < I would rather call my cmdExit procedure here, and omit the
following line
frmDataEntry.Caption = "The Close box has been de-activated! Please
click the exit button below!"
End Sub

D.S.



"Chip Pearson" wrote in message
...
DS,

You can use the QueryClose event procedure to catch the form's
closing via the 'X' button.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"D.S." wrote in message
...
I would like to prevent the user from closing a userform by

clicking the 'X'
on the right side of the titlebar. I need to force closure by

using a
command button, and running an exit procedure. Is there a

property setting
that will prevent this / or run the exit procedure when the 'X'

is clicked?

D.S.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default userform titlebar and closing form


That should be as easy as

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing with the Close box in the title bar.
If CloseMode < 1 Then Cancel = 1
cmdExit
End Sub

If cmdExiit is a button on the form, you would call the Click event and it
would then be

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing with the Close box in the title bar.
If CloseMode < 1 Then Cancel = 1
cmdExit_Click
End Sub

Either of these work?


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"D.S." wrote in message
...
I would like to run my "cmdExit" procedure here, if the user clicks the
close button, but I haven't had any luck. I get a syntax error. Can a
procedure be ran from here?


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing with the Close box in the title bar.
If CloseMode < 1 Then Cancel = 1
' < I would rather call my cmdExit procedure here, and omit the
following line
frmDataEntry.Caption = "The Close box has been de-activated! Please
click the exit button below!"
End Sub

D.S.



"Chip Pearson" wrote in message
...
DS,

You can use the QueryClose event procedure to catch the form's
closing via the 'X' button.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"D.S." wrote in message
...
I would like to prevent the user from closing a userform by

clicking the 'X'
on the right side of the titlebar. I need to force closure by

using a
command button, and running an exit procedure. Is there a

property setting
that will prevent this / or run the exit procedure when the 'X'

is clicked?

D.S.








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default userform titlebar and closing form

Thanks again. I forgot my exit code was triggered by an 'event'.

D.S.


"Bob Phillips" wrote in message
...

That should be as easy as

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing with the Close box in the title bar.
If CloseMode < 1 Then Cancel = 1
cmdExit
End Sub

If cmdExiit is a button on the form, you would call the Click event and it
would then be

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing with the Close box in the title bar.
If CloseMode < 1 Then Cancel = 1
cmdExit_Click
End Sub

Either of these work?


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"D.S." wrote in message
...
I would like to run my "cmdExit" procedure here, if the user clicks the
close button, but I haven't had any luck. I get a syntax error. Can a
procedure be ran from here?


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing with the Close box in the title bar.
If CloseMode < 1 Then Cancel = 1
' < I would rather call my cmdExit procedure here, and omit the
following line
frmDataEntry.Caption = "The Close box has been de-activated! Please
click the exit button below!"
End Sub

D.S.



"Chip Pearson" wrote in message
...
DS,

You can use the QueryClose event procedure to catch the form's
closing via the 'X' button.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"D.S." wrote in message
...
I would like to prevent the user from closing a userform by
clicking the 'X'
on the right side of the titlebar. I need to force closure by
using a
command button, and running an exit procedure. Is there a
property setting
that will prevent this / or run the exit procedure when the 'X'
is clicked?

D.S.










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform won't show after closing another file Gerry O Excel Discussion (Misc queries) 8 September 7th 07 03:51 PM
Re-show userform after closing file - code help Gerry O Excel Discussion (Misc queries) 3 September 4th 07 10:52 PM
Cant get a combo box to update without closing form justin Excel Discussion (Misc queries) 0 May 17th 06 09:06 PM
Closing a Form Mike Excel Discussion (Misc queries) 2 March 14th 06 01:09 PM
Help with closing a UserForm Ron de Bruin Excel Programming 0 August 8th 03 01:52 PM


All times are GMT +1. The time now is 09:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"