dbTalk Databases Forums  

Trap Closing Access

comp.databases.ms-access comp.databases.ms-access


Discuss Trap Closing Access in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
John von Colditz
 
Posts: n/a

Default Trap Closing Access - 03-25-2010 , 09:21 AM






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

Reply With Quote
  #2  
Old   
Rich P
 
Posts: n/a

Default Re: Trap Closing Access - 03-25-2010 , 10:37 AM






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/m...hide_close.php

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: Trap Closing Access - 03-25-2010 , 11:01 AM



John von Colditz wrote:
Quote:
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.

Reply With Quote
  #4  
Old   
John von Colditz
 
Posts: n/a

Default Re: Trap Closing Access - 03-25-2010 , 03:49 PM



It happens that Rich P formulated :
Quote:
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/m...hide_close.php

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Worked like a charm! Thanks!

Reply With Quote
  #5  
Old   
John von Colditz
 
Posts: n/a

Default Re: Trap Closing Access - 03-25-2010 , 03:50 PM



It happens that Salad formulated :
Quote:
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!

Reply With Quote
  #6  
Old   
Salad
 
Posts: n/a

Default Re: Trap Closing Access - 03-25-2010 , 05:30 PM



John von Colditz wrote:
Quote:
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!


The example Rich gave looked clean and easier to implement.

Reply With Quote
  #7  
Old   
The Frog
 
Posts: n/a

Default Re: Trap Closing Access - 03-29-2010 , 02:29 AM



Hi Salad,

You have nailed it in one. Our external field sales group use touch
screen laptops (not my idea). I tried to eliminate any inadvertant
'touches' that would cause operational problems. Since then I use it
with almost any app, and I leave the forms with their controls for the
users to operate. So far pretty clean. I am going to have a play with
the hiden form method - it seems messy to me. I like clean and
functional :-)

Cheers

The Frog

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.