[/FONT]
[FONT=Courier New]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[/FONT]
[FONT=Courier New]On Error GoTo ErrorHandling_Err
Const MF_BYCOMMAND = &H0&
Const MF_DISABLED = &H2&
Const MF_ENABLED = &H0&
Const MF_GRAYED = &H1&
Const SC_CLOSE = &HF060&[/FONT]
[FONT=Courier New]Dim lhWndMenu As Long
Dim lReturnVal As Long
Dim lAction As Long[/FONT]
[FONT=Courier New]lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0, Application.hWndAccessApp, lhWndTarget), False)[/FONT]
[FONT=Courier New]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[/FONT]
[FONT=Courier New]EnableDisableControlBox = lReturnVal[/FONT]
[FONT=Courier New]ErrorHandling_Err:
If Err Then
'Trap your error(s) here, if any!
End If
End Function