Solved

Application.Quit not working in Access 2010

Posted on 2010-11-12
8
3,044 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
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.

 
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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

821 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