Solved

Application.Quit not working in Access 2010

Posted on 2010-11-12
8
2,998 Views
Last Modified: 2012-06-21
Hi,

i have written my company's stock system in an Access 2007 front end connecting to a MS SQL server for the Database.

I want to roll out Access 2010 and am testing it on the development machine.

There seem to be a couple of issues, but i have one that i can't get past.

In the database there is a main form. When that form is closed - it triggers the Form_Unload event.. and in that event the code Application.Quit is called and the application quits.

In Access 2007 and 2010 - if you close the main form the application exits properly.

BUT....

in Access 2007 - if you click the click on the X button in the top right hand corner of the access application (not the main form), it causes the main form to close and the application.quit runs and the application exits properly.

in Access 2010 - if you click the click on the X button in the top right hand corner of the access application, it causes the main form to close but it ignores the application.quit code and continues past it and code runs that should not run.

can anyone explain why the Application.Quit is iqnored in Access 2010 when you close the database from the top right and X button?

thanks

jack
0
Comment
Question by:jackbenson
8 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 42 total points
ID: 34119181
I agree with your description of the situation.

But I'm not quite clear what sort of code you would put after an unconditional  .quit command.
Under what circumstances woud you be expecting it to run?

This might be a bug or it might be MS being 'clever' ("If i'm in the middle of a .quit then ignore any further .quit commands") and not seeing the whole picture.

In my view this is an unusual approach - I would have said that the more common situation would be that developers would be using the form_unload event procedure to PREVENT someone closing the app using the Access X and forcing them into an orderly shutdown, if that's what they intended.  So it might be something that escaped MS.
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 41 total points
ID: 34119214
I'd use the Form's Close event for this, since it cannot be canceled. The order of events for this is

Unload - Deactivate - Close

Since Close is the LAST event, and you're trying to exit the app, then move your code there.
0
 
LVL 1

Author Comment

by:jackbenson
ID: 34127664
i dont know how it can be happening... but when you close the access database from the X in the top right hand corner (is there a technical name for this button?) the following events are called in the following order on the form that controls the database:

Form_Unload()
Form_Load()

i cant understand why the Form_Load() would be called at all. there are no references to it. i have prooved it by putting msgbox commands in the Form_Load()

there is a load of code that runs in the Form_Load that should not run again after it has been run once.

can anyone replicate this?

thanks

jack
0
 
LVL 84
ID: 34127956
Any code that could Load the form in ANY event?

Any Subforms on that form?

If you have a situation where Events are being called out of order, you might have a corrupt database. Have you tried Compacting the database?

If that doesn't help, a Decompile might be in order. Build a Shortcut and set the Target to this:

"full path to msaccess.exe" "full path to the database" /decompile

Run this, then Compact again.

If those don't help, then try building a new, blank database and importing everything into that new database.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 1

Author Comment

by:jackbenson
ID: 34128224
the decompile / compact did not help.

i will build a new database and import everything and will let you know how it goes

thanks

jack
0
 
LVL 10

Assisted Solution

by:t_hungate
t_hungate earned 42 total points
ID: 34131950
Perhaps adding to you On Load code to check and see if the form has already been loaded.  If so, then exit your routine.  That should prevent the code from running during the Unload, or Close of the form.
0
 
LVL 1

Author Comment

by:jackbenson
ID: 34132046
thanks, thats what i have done..  i have got round it by putting a if statement that checks if the startup operations have already run. if they have it exits the Form_Load()

i will have a good look though my code at some point to work out what is causing this problem

thanks for all your help.

jack
0
 
LVL 1

Author Closing Comment

by:jackbenson
ID: 34132051
thanks for all your help!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now