Prevent ACCESS 2007 Form from Closing Though X:

pedie

Registered User.
Local time
Today, 13:36
Joined
Aug 3, 2011
Messages
20
Hi please help me with vba to prevent ACCESS 2007 Form from Closing Though X but only through Exit button.
Thanks
 
I exactly tried this way nothing happend when i close my form...
It did not disable my form from being closed/by clicking on X....

Thanks again
Code:
[/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
 
Try reading his instructions word by word. You have not done what he suggested so of course it did not work.
 

Users who are viewing this thread

Back
Top Bottom