Place the following code in a new module:
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 EnableDisableCloseButton(bEnable As Boolean, _
Optional ByVal lhWndTarget As Long = 0) As Long
Dim lhWndMenu As Long
Dim lReturnVal As Long
Dim lAction As Long
Const MF_BYCOMMAND = &H0&
Const MF_DISABLED = &H2&
Const MF_ENABLED = &H0&
Const MF_GRAYED = &H1&
Const SC_CLOSE = &HF060&
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
EnableDisableCloseButton = lReturnVal
ErrorHandling_Err:
If Err Then
MsgBox Err.Number & ":" & Err.Description
End If
End Function
Now ... in the first form of your application that opens .. place the following in the "On Load" event of the form:
CODE
Private Sub Form_Load()
EnableDisableCloseButton False
End Sub
The above code will disable the Close Button in Access.
Now add the following code to your Exit or Close button in your application:
CODE
Private Sub cmdExit_Click()
EnableDisableCloseButton True
DoCmd.Quit
End Sub
RDH