none
How to disable X button in top right-hand corner? RRS feed

  • Question

  • I have special code in all my applications that is supposed to disable the X button for closing a window.

    I always use a [Close] button that performs custom logic.

    However, in one database, the user reports (and I have verified) that the X button has become active on one screen.

    What is the correct way to disable this button?

    Here is the code that used to work:

    Function InitApplication()
       On Error GoTo ER
       Dim c As CloseCommand
       Set c = New CloseCommand
       
       'Disable Close menu.
       c.Enabled = False   

       Exit Function
    ER:
       MsgBox Err.Description, , "InitApplication"
    End Function

    Friday, September 6, 2019 9:39 PM

All replies

  • In the form's module's declarations area declare a variable of Boolean data type:

        Private AllowClose As Boolean

    In the form's Unload event procedure cancel the event if the variable is not TRUE:

        Cancel = Not AllowClose

    In the command button's Click event procedure set the variable to TRUE and close the form:

        AllowClose = True
        DoCmd.Close acForm, Me.Name

    Ken Sheridan, Stafford, England

    Friday, September 6, 2019 10:48 PM
  • I do not know (I forget) the details of Access events but certainly there is an event for when the form closes. A better solution would be to process that event and do the special code in that event. You can make a common subroutine (or whatever you call it) that is called from both places, the button click and the x click.

    And I know as much as you how hot and humid it has been here in the Southwestern USA.



    Sam Hobbs
    SimpleSamples.Info

    Saturday, September 7, 2019 1:57 AM
  • If you want to disable the close button the solution is API  .... Check here : https://www.fmsinc.com/microsoftaccess/startup/preventclose.asp
    Saturday, September 7, 2019 10:46 AM