Stop Close Form Button Working On Userforms

  • Hi All,


    I have a useform that loads up with two buttons and I waat to force the user to chose one of the buttons. However, I have noticed that the user can just press the cross in the top right corner of the form to close the window and therefore not press either button.


    Is there anyway I can stop the close form button working?


    Thanks


    James

  • Re: Stop Close Form Button Working On Userforms


    credit to j walkenbach, put this in the ThisWorkbook code module:


    Code
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
        MsgBox "click the OK button to close"
        Cancel = True
        End If
    End Sub


    p45cal

  • Re: Stop Close Form Button Working On Userforms


    Here are a couple more to try.


    From Norie:

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


    From Erik

    Code
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) 
    Dim msg As String 
    msg = "you cannot close this form with the """"X""" & Chr(10) & "Please use the ...button" 
        If CloseMode = 0 Then 
        Cancel = True 
        MsgBox msg, 48, "USE BUTTON TO CLOSE" 
        End If 
    End Sub


    HTH
    Regards
    John

  • Re: Stop Close Form Button Working On Userforms


    Ah, Brilliant!


    Yes, All those variations work perfectly!


    Thanks you very much guys for your expert assistance!


    James

Participate now!

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