ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform close (https://www.excelbanter.com/excel-programming/407464-userform-close.html)

Karen53

Userform close
 
Hi,

I need to intercept when the user clicks the 'X' on the title bar to close
the userform instead of my 'Close' button and run code.

In researching on the newsgroup I found two sets of code. I am wondering
what the difference is between the two and which would be better to use.

Choice 1:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
MsgBox "This option will not close the form"
Cancel = 1
End If
End Sub

Choice 2:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = vbFormControlMenu Then
' make user do what you want"
Cancel = True
End If
End Sub

--
Thanks for your help.
Karen53

Nigel[_2_]

Userform close
 
They are essentially the same, vbFormControlMenu refers to the 'X' as the
mode of closing. CloseMode = 0 is the same. Cancel = 1; evaluates to
True.

I use, CloseMode = 0 and Cancel = True

--

Regards,
Nigel




"Karen53" wrote in message
...
Hi,

I need to intercept when the user clicks the 'X' on the title bar to close
the userform instead of my 'Close' button and run code.

In researching on the newsgroup I found two sets of code. I am wondering
what the difference is between the two and which would be better to use.

Choice 1:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
MsgBox "This option will not close the form"
Cancel = 1
End If
End Sub

Choice 2:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = vbFormControlMenu Then
' make user do what you want"
Cancel = True
End If
End Sub

--
Thanks for your help.
Karen53



Howard Kaikow

Userform close
 
"Nigel" wrote in message
...
They are essentially the same, vbFormControlMenu refers to the 'X' as the
mode of closing. CloseMode = 0 is the same. Cancel = 1; evaluates to
True.

I use, CloseMode = 0 and Cancel = True


Cancel is an Integer data type, so Cancel = 1 is the preferred coding.

Shhh, don't tell anyone, this is a secret, I've probably done it both ways.



Karen53

Userform close
 
Thank you, Nigel.

--
Thanks for your help.
Karen53


"Nigel" wrote:

They are essentially the same, vbFormControlMenu refers to the 'X' as the
mode of closing. CloseMode = 0 is the same. Cancel = 1; evaluates to
True.

I use, CloseMode = 0 and Cancel = True

--

Regards,
Nigel




"Karen53" wrote in message
...
Hi,

I need to intercept when the user clicks the 'X' on the title bar to close
the userform instead of my 'Close' button and run code.

In researching on the newsgroup I found two sets of code. I am wondering
what the difference is between the two and which would be better to use.

Choice 1:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
MsgBox "This option will not close the form"
Cancel = 1
End If
End Sub

Choice 2:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = vbFormControlMenu Then
' make user do what you want"
Cancel = True
End If
End Sub

--
Thanks for your help.
Karen53



Karen53

Userform close
 
LOL, Thanks Howard
--
Thanks for your help.
Karen53


"Howard Kaikow" wrote:

"Nigel" wrote in message
...
They are essentially the same, vbFormControlMenu refers to the 'X' as the
mode of closing. CloseMode = 0 is the same. Cancel = 1; evaluates to
True.

I use, CloseMode = 0 and Cancel = True


Cancel is an Integer data type, so Cancel = 1 is the preferred coding.

Shhh, don't tell anyone, this is a secret, I've probably done it both ways.





All times are GMT +1. The time now is 06:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com