Solved

Application.Quit not working in Access 2010

Posted on 2010-11-12
8
2,977 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

21 Experts available now in Live!

Get 1:1 Help Now