Close button

sven2

Registered User.
Local time
Today, 12:18
Joined
Apr 28, 2007
Messages
297
Hello,

in my access application I have made a button to close this application and make a log. Now when somebody hit the cross in the right corner to close access I have a problem with my logtable. I know you can disable this button but I want to do the following:

when somebody hit this button there should be a message on the screen that says this button is out of order ...

and access neither the forms should not close ...

How can you do that in access?

Best regards,
Sven.
 
in the form close event put something like

either

msgbox("You cant quit the app with the close button")
cancel = vbcancel

or

if msgbox("You are quitting the app - are you sure",vbquestion+vbyesno)=vbno then
cancel = vbcancel
exit sub
end if

or disable the close button on the form. and provide your own close button.

------
you probably need the event handler though, as if users dont see the x close button they might just quit access directly, which puts you back where you started
 
The EASIEST way is to have your app open a hidden form when it opens and in that form's unload event use:

Code:
If blnClose = False Then
    MsgBox "You can't quit the application by clicking the X." & VbCrLf & _
    "Please close using the correct button.",vbExclamation, "Close Error"
    Cancel = True
    If Not CurrentProject.AllForms("YourMainFormNameHere").IsLoaded Then
          DoCmd.Open "YourMainFormName"
    End If
End If

And in the General Declarations Section of a Standard Module you create a boolean variable of

Code:
Public blnClose As Boolean

And then in the code for your close button on your form(s) you add:

Code:
blnClose = True

And that way Access knows that the form was closing the app, but if the boolean hasn't been set then it won't allow them to exit.
 

Users who are viewing this thread

Back
Top Bottom