Question Stopping Use of X

matthewnsarah07

Registered User.
Local time
Today, 09:33
Joined
Feb 19, 2008
Messages
192
I'm sure this has been mentioned before but I couldn't find a thread.

How do I ensure that a database users work is always saved even if they exit using the X on the main access window?

Is it possible to disable the X in the same way as forms?

Thanks
 
Not easily, no. If your forms are bound to tables/queries, Access will automatically try to save the data if the application is closed.
 
The best solution I ever found for this was to have a bit of code in the form OnUnload event that if it was still dirty, it did a Cancel on the event. If you cannot unload the form, you will not close the app either. But you have to put this on every form that could have dirty data. Not a pretty sight and damned tedious to visit every form. But it saved my buns at least a couple of times, I'm sure.
 
Found this on the net:

Code:
This sample will show you how to disable the little 'X' close button found on the upper right of 
every window. To do this what we will do is use a couple of API calls to remove the Close menu 
item from the windows system menu. Doing this will disable the close button. When you try 
out this sample, you may want to have an alternate way to close your window.
Insert this code into a .bas module
Option Explicit

Public Declare Function GetSystemMenu Lib "user32" _
    (ByVal hwnd As Long, _
     ByVal bRevert As Long) As Long

Public Declare Function RemoveMenu Lib "user32" _
    (ByVal hMenu As Long, _
     ByVal nPosition As Long, _
     ByVal wFlags As Long) As Long

Public Const MF_BYPOSITION = &H400&


Public Sub DisableCloseWindowButton(frm As Form)

    Dim hSysMenu As Long

    'Get the handle to this windows
    'system menu
    hSysMenu = GetSystemMenu(frm.hwnd, 0)

    'Remove the Close menu item
    'This will also disable the close button
    RemoveMenu hSysMenu, 6, MF_BYPOSITION

    'Lastly, we remove the seperator bar
    RemoveMenu hSysMenu, 5, MF_BYPOSITION

End Sub
'--end code block
Now call the DisableCloseWindowButton from your forms load event.
Private Sub Form_Load()
    DisableCloseWindowButton Me
End Sub
'--end code block
 

Users who are viewing this thread

Back
Top Bottom