Consulting

Results 1 to 4 of 4

Thread: Preventing a form from closure

  1. #1
    VBAX Tutor SJ McAbney's Avatar
    Joined
    May 2004
    Location
    Glasgow
    Posts
    243
    Location

    Preventing a form from closure

    So, how do I prevent someone from closing a form in Excel. I can't find any Cancel event.

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    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

  4. #4
    VBAX Tutor SJ McAbney's Avatar
    Joined
    May 2004
    Location
    Glasgow
    Posts
    243
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •