Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    37

    Unanswered: Event/API when MS Access is closed by the user by the X button

    Can anyone tell me if they know of an event or an API I can use which will fire when the user clicks the X button in MS Access (I want to call some code to perform an automatic backup)?

  2. #2
    Join Date
    Jun 2004
    Posts
    10
    Why you don't try to disable the X button ??
    here is the function that u can use, i was used in my application !
    hope this could help u, enjoy it !!

    Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long

    Function DisableAccessClose()
    Dim M As Long
    Dim btn_CLOSE As Long
    Dim btn_STATE As Long
    Dim hMenu As Long
    btn_STATE = &H3&
    btn_CLOSE = &HF060&
    hMenu = GetSystemMenu(Application.hWndAccessApp, &H0&)
    M = EnableMenuItem(hMenu, btn_CLOSE, btn_STATE)
    End Function
    Function EnableAccessClose()
    Dim M As Long
    Dim btn_CLOSE As Long
    Dim btn_STATE As Long
    Dim hMenu As Long
    btn_STATE = &H8&
    btn_CLOSE = &HF060&
    hMenu = GetSystemMenu(Application.hWndAccessApp, 0)
    M = EnableMenuItem(hMenu, btn_CLOSE, btn_STATE)
    End Function

  3. #3
    Join Date
    Feb 2004
    Posts
    37
    Thanks,

    Thought of that one, but my boss doesn't like it.

    Have found a sort of solution (it works but ain't pretty).
    Created a hidden form which never gets unloaded through our code. Then when MS Access tries to shut down it will automatically close all forms (going through each of their unload event), as by this time, the new form is the only one still loaded - it's unload event is the last thing MS Access will fire while closing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •