• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Ms Access control an unintended close of the application

I have a main form with a close button that has code that tests for the unintended exit of the app.  This works fine.  Any attempt to put similar code in the form unload event does not work.  Users sometimes mistakenly hit the close control on the main menu.  Is there a way to catch that and cancel the closing of MS Access?  Thanks
1 Solution
Guru JiCommented:
You can't cancel the close event but you can cancel the unload event, so you can put this in your unload event and it will prompt you when closing.

Private Sub Form_Unload(Cancel As Integer)

    If MsgBox("Test", vbYesNo + vbExclamation, "Confirm close") <> vbYes Then
         Cancel = True
    End If

End Sub
SbovinoAuthor Commented:
Thanks, Worked perfectly!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now