PDA

View Full Version : SOLVED: Preventing a form from closure



SJ McAbney
08-09-2004, 03:44 AM
So, how do I prevent someone from closing a form in Excel. I can't find any Cancel event.

TonyJollans
08-09-2004, 05:08 AM
The QueryClose Event is the one you want. You can check how the request to close was made and Cancel the close if you see fit.

Jacob Hilderbrand
08-09-2004, 05:41 AM
To follow up on Tony's suggestion, try this code:


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

SJ McAbney
08-09-2004, 05:46 AM
Thanks for that. I'd looked at that event's name and thought it was something to do with using MS Query and a form. Makes sense now.

This nicely sorts the problem.


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