none
Disable Close by right click on tab RRS feed

  • Question

  • Hi 

    I want to force the user to click a button to close a form. Therefore, need to be able to turn off the option to right-click on the form's tab and select Close. Can it be done?


    Cheers // Peter Forss Stockholm

    Friday, March 27, 2020 8:00 AM

Answers

  • 1) Declare a variable at the top of the form module:

    Private CanClose As Boolean

    2) Create an On Unload event procedure for the form:

    Private Sub Form_Unload(Cancel As Integer)
        Cancel = Not CanClose
    End Sub

    3) Make the code for the command button look like this:

    Private Sub cmdClose_Click()
        CanClose = True
        DoCmd.Close acForm, Me.Name
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Friday, March 27, 2020 8:18 AM

All replies

  • 1) Declare a variable at the top of the form module:

    Private CanClose As Boolean

    2) Create an On Unload event procedure for the form:

    Private Sub Form_Unload(Cancel As Integer)
        Cancel = Not CanClose
    End Sub

    3) Make the code for the command button look like this:

    Private Sub cmdClose_Click()
        CanClose = True
        DoCmd.Close acForm, Me.Name
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Friday, March 27, 2020 8:18 AM
  • Thank you very much Hans

    Cheers // Peter Forss Stockholm

    Friday, March 27, 2020 8:42 AM