Proper closing of database

rbrule

Registered User.
Local time
Today, 05:30
Joined
Jan 13, 2004
Messages
108
I recently created a database and installed buttons to properly close the database to avoid coruption of files etc. However I could not find a way to eliminate the X button in the upper right corner of access. Today my dbase crashed, I presume because someone did not use the buttons I installed, and just closed using the X in the upper right corner of access. The database is on a network, and was not password protected at the time. It will be when it is restored, however I would still like to know if there is a way to eliminate the x button in the upper right hand corner so that users will have to use the buttons created to properly close the database.
 
Thank you but my machine will not let me open the file. Is the process of disabling the X a complicated one?
 
Here is the code taken from the example, cut and paste it into a standard module and call using this

EnableDisableControlBox(False)

Code:
Option Compare Database
Option Explicit

'Calvin Smith
'http://www.CalvinSmithSoftware.com/codedisk/sneakpeek.htm

'**********************************************************
'************ Code provided by CodeDisk II ****************
'**********************************************************

'We need the following API declarations first
Public Declare Function apiEnableMenuItem Lib "user32" Alias "EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As Long, ByVal wEnable As Long) As Long
Public Declare Function apiGetSystemMenu Lib "user32" Alias "GetSystemMenu" (ByVal hWnd As Long, ByVal flag As Long) As Long

Public Function EnableDisableControlBox(bEnable As Boolean, Optional ByVal lhWndTarget As Long = 0) As Long
On Error GoTo ErrorHandling_Err

    ' ----------------------------------------------------------------------
    ' Purpose: Example of how to disable or enable the control box of
    '          a form, report, or the Access parent window.
    '
    ' Accepts: bEnable, which determines whether to disable or enable
    '          the control box
    '
    '          Also accepts lhWndTarget (which is optional), if you want
    '          to use a window handle other than the Access parent window.
    '
    ' Returns: N/A
    '
    ' Example usage: lRetVal = EnableDisableControlBox(True) to enable -OR-
    '                lRetVal = EnableDisableControlBox(False) to disable
    '
    ' NOTE: If no hWnd is passed in for a specific form, then the code
    '       assumes you want to enable/disable the Access parent window
    ' ----------------------------------------------------------------------

    Const MF_BYCOMMAND = &H0&
    Const MF_DISABLED = &H2&
    Const MF_ENABLED = &H0&
    Const MF_GRAYED = &H1&
    Const SC_CLOSE = &HF060&
    
    Dim lhWndMenu As Long
    Dim lReturnVal As Long
    Dim lAction As Long
    
    lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0, Application.hWndAccessApp, lhWndTarget), False)
    
    If lhWndMenu <> 0 Then
         If bEnable Then
            lAction = MF_BYCOMMAND Or MF_ENABLED
         Else
            lAction = MF_BYCOMMAND Or MF_DISABLED Or MF_GRAYED
         End If
         lReturnVal = apiEnableMenuItem(lhWndMenu, SC_CLOSE, lAction)
    End If
    
    EnableDisableControlBox = lReturnVal
    
ErrorHandling_Err:
        If Err Then
            'Trap your error(s) here, if any!
        End If
    
    End Function

good luck, Scott
 
Thanks Scott, I appreciate your help.

Ron
 

Users who are viewing this thread

Back
Top Bottom