Cancel terminate event??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

Helps from you all are much appreciate!
 
Pop said:
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 *
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top