From: John von Colditz on
I am modifying an existing application for a client. None of the forms
has a close or exit button, so users are in the habit of just clicking
on the X in the upper right of the forms. I was informed today that
users occasionally click the X for the application by mistake, and the
entire database closes. How do I trap that in code, give a Yes/No
option on closing, and then cancel if necessary?

Thanks!

John


From: Rich P on
I don't believe Access has an event for Application_Close, but what you
could try would be to disable the close button and make it so users
could only close the app from a designated Quit Button. Here is a link
for code to disable the Close button for the respective app:

http://www.techonthenet.com/access/modules/hide_close.php

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***
From: Salad on
John von Colditz wrote:
> I am modifying an existing application for a client. None of the forms
> has a close or exit button, so users are in the habit of just clicking
> on the X in the upper right of the forms. I was informed today that
> users occasionally click the X for the application by mistake, and the
> entire database closes. How do I trap that in code, give a Yes/No option
> on closing, and then cancel if necessary?
>
> Thanks!
>
> John
>
>
I did this with very little testing. It appears to work, but I'd test
further.

I created a module. The code is
Public Function OpenApp() As Boolean
DoCmd.OpenForm "Table1", , , , , acHidden
DoCmd.OpenForm "Junk"
OpenApp = True
End Function

That opens form Table1 invisible and form Junk as visible.

Form Table1 is a bound form to table Table1 (a table with 2 fields;
TestID and Test). I added the a checkbox field to the form called
CloseIt. When the form is opened I set a value, "New Data" to the
"Test" field simply to dirty the record. On the Unload I check for the
value of the checkbox CloseIt. The default value of CloseIt is false.
If closeit is true, the app shuts down. If false, the user is asked
whether the app should be closed.
Private Sub Form_Current()
Me.Test = "New Data"
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not Me.CloseIt Then
If MsgBox("Close the app?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
End If
Me.CloseIt = False
Else
Me.Undo
End If
End Sub


The form Junk opens up. If the op presses the Exit button, it sets the
CloseIt checkbox to True in form Table1. Thus if I press the Exit
button, the app quits. If I press the X button to close Access, I am
prompted and asked whether or not I want to exit the app. If I answer
Yes, CloseIt in form Table1 is set to true and the app quits. If I
answer No, from Junk remains open like I did nothing.
Private Sub CommandExit_Click()
Forms!Table1!CloseIt = True
Application.Quit
End Sub

I have an Autoexec macro that RunCode's "OpenApp" when the app loads.
Personally, I'd add the Min/Max/Close buttons to the forms.
From: John von Colditz on
It happens that Rich P formulated :
> I don't believe Access has an event for Application_Close, but what you
> could try would be to disable the close button and make it so users
> could only close the app from a designated Quit Button. Here is a link
> for code to disable the Close button for the respective app:
>
> http://www.techonthenet.com/access/modules/hide_close.php
>
> HTH
>
> Rich
>
> *** Sent via Developersdex http://www.developersdex.com ***

Worked like a charm! Thanks!


From: John von Colditz on
It happens that Salad formulated :
> John von Colditz wrote:
>> I am modifying an existing application for a client. None of the forms has
>> a close or exit button, so users are in the habit of just clicking on the X
>> in the upper right of the forms. I was informed today that users
>> occasionally click the X for the application by mistake, and the entire
>> database closes. How do I trap that in code, give a Yes/No option on
>> closing, and then cancel if necessary?
>>
>> Thanks!
>>
>> John
>>
>>
> I did this with very little testing. It appears to work, but I'd test
> further.
>
> I created a module. The code is
> Public Function OpenApp() As Boolean
> DoCmd.OpenForm "Table1", , , , , acHidden
> DoCmd.OpenForm "Junk"
> OpenApp = True
> End Function
>
> That opens form Table1 invisible and form Junk as visible.
>
> Form Table1 is a bound form to table Table1 (a table with 2 fields; TestID
> and Test). I added the a checkbox field to the form called CloseIt. When
> the form is opened I set a value, "New Data" to the "Test" field simply to
> dirty the record. On the Unload I check for the value of the checkbox
> CloseIt. The default value of CloseIt is false. If closeit is true, the app
> shuts down. If false, the user is asked whether the app should be closed.
> Private Sub Form_Current()
> Me.Test = "New Data"
> End Sub
> Private Sub Form_Unload(Cancel As Integer)
> If Not Me.CloseIt Then
> If MsgBox("Close the app?", vbYesNo, "Confirm") = vbNo Then
> Cancel = True
> End If
> Me.CloseIt = False
> Else
> Me.Undo
> End If
> End Sub
>
>
> The form Junk opens up. If the op presses the Exit button, it sets the
> CloseIt checkbox to True in form Table1. Thus if I press the Exit button,
> the app quits. If I press the X button to close Access, I am prompted and
> asked whether or not I want to exit the app. If I answer Yes, CloseIt in
> form Table1 is set to true and the app quits. If I answer No, from Junk
> remains open like I did nothing.
> Private Sub CommandExit_Click()
> Forms!Table1!CloseIt = True
> Application.Quit
> End Sub
>
> I have an Autoexec macro that RunCode's "OpenApp" when the app loads.
> Personally, I'd add the Min/Max/Close buttons to the forms.

Too much going on with my application closing, and I couldn't make this
work!

Thanks anyway!