Preventing Form Dialog dismiss (Red X)

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

Guest

I want to detect if someone click the Red X to dismiss the form instead of my
OK or Cancel command buttons. Even better would be to prevent the form from
being dismissed in the first place.

I looked in the Object Browser for UserForm and did not find a BeforeUnload
event. I see the Terminate event, but it appears this is too late to prevent
the form from being terminated.

Is there something I'm missing?

inTHANKSadvance
 
Jim,

You can use the userform QueryClose event to prevent the form from closing.

Something like...

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = True
MsgBox "Please use the cancel button to exit. "
End Sub

Regards,
Jim Cone
San Francisco, USA


I want to detect if someone click the Red X to dismiss the form instead of my
OK or Cancel command buttons. Even better would be to prevent the form from
being dismissed in the first place.

I looked in the Object Browser for UserForm and did not find a BeforeUnload
event. I see the Terminate event, but it appears this is too late to prevent
the form from being terminated.

Is there something I'm missing?

inTHANKSadvance
 
This might be even more useful...

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then
Cancel = True
MsgBox "Please use the cancel button to exit. "
End If
End Sub


Jim Cone
 

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