Userform Query_Close() question

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
R

Robert Crandal

Does anybody know where I can find a good
reference to the userform Query_Close() function???

I would like more information on how to use the
"Cancel" and "CloseMode" parameters.

thank you
 
It's pretty simple.

Click the red X top right, a common way to close windows, and it's CloseMode
0.
Close the form by code (like Unload Me from a button) and it's CloseMode 1.

Cancel is set to stop the close operation. If a checkbox1 says "I accept the
license agreement" then this code keeps the form open until the box is
checked:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If Me.CheckBox1.Value = False Then
Cancel = True
MsgBox "You must agree with us first"
End If
End Sub

Or if you simply want to disable the red X:

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

HTH. Best wishes Harald
 
Back
Top