Disable control exit event when quitting a user form

  • I have designed a user form with data validation triggered by the exit event of each textbox.
    If I decide to quit the userform using the X in the top right corner I want to disable the exit event that is triggered by this action.
    Is this possible? I am trying to cover the situation where a user decides to quit an input process when they are told data is invalid, possibly to go and find the correct information before attempting to enter the information again.

  • Re: Disable control exit event when quitting a user form


    Yes.. very easily done.


    below is an example of what I use. In my userforms I have a cancel button that performs some background stuff, so I force a prompt to the user to use the cancel button.

    Code
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        If CloseMode = vbFormControlMenu Then
            Cancel = True
            MsgBox ("Must select Cancel in order to close Form")
        End If
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!