Solved

Application.Quit not working in Access 2010

Posted on 2010-11-12
8
3,021 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Normalization of a table 19 75
Allow user to edit an outgoing email 2 25
VBA SQL statement - 2 "OR"s and 1 "And" 4 27
Progress bar in access form 11 25
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…
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 stored procedures 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 Micr…
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.

803 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