"Pop" wrote in message
...
I wonder how to cancel a terminate event?
If I invoke a terminate event by pressing the X button on the top right
corner, then I ask does user really want to terminate,
then how am I going to cancel the terminate event if user click no?
Hi Pop,
You can't cancel the Terminate event of a UserForm. Once your code has
reached that point it's too late. What you need to trap is the QueryClose
event instead. This event fires when anything attempts to close the UserForm
and gives you the option to cancel. Here's a basic example:
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
' If our code is not closing the form, ask the
' user if this is really what they want to do.
If CloseMode < vbFormCode Then
If MsgBox("Do you want to close", vbYesNo) = vbNo Then
Cancel = True
End If
End If
End Sub
--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/
* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *