Keep Access Open Question

mrgreen

Registered User.
Local time
Today, 00:36
Joined
Jan 11, 2008
Messages
60
Not sure if my quetion goes in this section but I'll give it a shot. I currently have managers entering their daily production numbers (Access 2003 FE/BE) and at the end is a summary form that "spits" out the results and they are required to enter information as to why they didn't achieve their targets (or what went well during their shift) and what measures they put in place to achieve them next time.
This all works great but if they aren't sure what to say or they just don't feel like saying anything they go ahead and close Access. This is obviously a behavioral issue but I was wondering if there was a way to prevent them from closing Access prior to meeting the criteria. The functionalility to go back at a later time and edit the information exists so just entering the letter "a" would work but it's more of a soar spot for me to not allow them to just close the program. :mad:

Thoughts?:confused:
 
Not sure if my quetion goes in this section but I'll give it a shot. I currently have managers entering their daily production numbers (Access 2003 FE/BE) and at the end is a summary form that "spits" out the results and they are required to enter information as to why they didn't achieve their targets (or what went well during their shift) and what measures they put in place to achieve them next time.
This all works great but if they aren't sure what to say or they just don't feel like saying anything they go ahead and close Access. This is obviously a behavioral issue but I was wondering if there was a way to prevent them from closing Access prior to meeting the criteria. The functionalility to go back at a later time and edit the information exists so just entering the letter "a" would work but it's more of a soar spot for me to not allow them to just close the program. :mad:

Thoughts?:confused:


I like to use this method:

Prevent Access from closing

This technique can also be used for any form
 
Boyd's post links to the way it is done from inside Access but here is an interesting angle on the problem for any window you would like to stop being closed by the Close button.

No Close greys out and disables the Close button. It is a small, free, easy to use program.
Find it on this page:
http://www.donationcoder.com/Software/Skrommel/

I have used it for a long time on XP without any problems.
I would love to know how to do it from VBA.

There are a couple of others that could be interesting too but also a lot of unlikely ones.
 
Last edited:
Boyd's post links to the way it is done from inside Access but here is an interesting angle on the problem for any window you would like to stop being closed by the Close button.

No Close greys out and disables the Close button. It is a small, free, easy to use program.
Find it on this page:
http://www.donationcoder.com/Software/Skrommel/

I have used it for a long time on XP without any problems.
I would love to know how to do it from VBA.

There are a couple of others that could be interesting too but also a lot of unlikely ones.

Is this the Windows API you are looking for:

Code:
Private Declare Function apiEnableMenuItem Lib "user32" Alias _
    "EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As Long, _
     ByVal wEnable As Long) As Long
     
Private Declare Function apiGetSystemMenu Lib "user32" Alias _
         "GetSystemMenu" (ByVal hwnd As Long, ByVal flag As Long) _
         As Long
'
'
'

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
'
'
'
'
Public Function HideAccessCloseButton()

    EnableDisableControlBox False
    
End Function

Public Function ShowAccessCloseButton()

    EnableDisableControlBox True
    
End Function
 
Is this the Windows API you are looking for:

I'm running Access 2007 on XP Professional and it doesn't work. I expect it was written for Windows 9x or earlier versions of Access. I only tried it on the main window. Access 2007 can disable its own internal window buttons anyway.

The functions draw a little window with a set of buttons more or less on top of the standard buttons for the main program window. The Disable and Enable functions grey out or redraw the Close button in this group.

However passing the mouse over the little button window makes it disappear.

Note that even if the button was disabled the programs can still close with an exit command so the technique in the link still needs to be used to prevent with an exit command.

BTW:
No Close does work in Office programs but it does not effect the appearance of the Close button.

It is a simple 200KB executable and does not need installing. It writes a plain text ini file in the same folder as the exe. However it gives away its presence with a Tray icon.

It would really a bit of a kludge to use it for an Access application but it is a great little tool to prevent accidentally closing the wrong window on a messy desktop.
 
Last edited:
Maybe too simple but under the close button of the form you could do something like

Dummy code...
Code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

If Me.ImproveTargetsField = ""

Then MsgBox "Please give some feedback on your performance prior to closing this form"

Me.ImproveTergetsField.SetFocus

Else If

Close

End If

That way at least they are taken back to the field that you are particularly intereted in.

Could also probably make it so it looked to see if all of the fields that you were interested in were blank. First line required to save a new record prior to the IF test.

Maybe not stop them closing the program if they are determined but might make it a bit more awkward.
 
Last edited:
Not to mention that there is a Form_Unload event that can be canceled. If you cancel the Unload, you cannot close the form. If you cannot close the form, you cannot close Access without pretty dire consequences.
 

Users who are viewing this thread

Back
Top Bottom