Hi please help me with vba to prevent ACCESS 2007 Form from Closing Though X but only through Exit button.
Thanks
Hi please help me with vba to prevent ACCESS 2007 Form from Closing Though X but only through Exit button.
Thanks
How about just disabling the "X" when you start?
http://www.calvinsmithsoftware.com/D...ControlBox.htm
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: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 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
I see you answered the same way in AWF. Did you call this code from your opening form? EnableDisableControlBox(False)
RuralGuy, my apologies I tried my luck in anoother forum too...
I enter the whole code in standard module
and then in the load event of the form i enterd
Code:Private Sub Form_Load() EnableDisableControlBox (False) Me.Username2.Value = UCase(Environ("Username")) End Sub
This is the form where i do not want user to close the form from X...
Thanks again, appriciate your help.
To start, there is no space before the open paren: EnableDisableControlBox(False)
This disables the X for Access but *not* the form. Each form has a property for that and you can set it in design view of the form.
RuralGuy, thanks alot.... i really appriciate your help...
I got it wrong..i thought this is for access form and not application.
How can i prevent the form from closing? Please
Thanks again
Create a public Boolean variable in your form (before any procedures). Set it true behind your Exit button and also DoCmd.Close acForm, Me.Name, acSaveNo. Then test the Boolean value in the UnLoad event and Cancel = True if the Boolean value is still False.
Thanks again...that solves it...
Thank you very much!
Glad we could help.