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

Stopping Form from Unloading

How do I stop the application from unloading if the window close button (X - top right-hand side of the window ) has been clicked in error. I can interrupt the unload event to safeguard data, but using 'exit sub' does not give me the desired affect.
1 Solution
Check out the QueryUnload event, if the variable 'UnloadMode' is equal to vbFormControlMenu then the user has used the 'X' button to close the window. Change the value of the variable 'Cancel' to True to abort unloading.

Somehting like this..

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

  If (UnloadMode = vbFormControlMenu) Then
    Cancel = True
  End If
End Sub

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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