Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Not Closing Properly

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
US
All, I have a custom menu with a "shut down" database selection.

When this item is selected it does the following command ...

Code:
DoCmd.Quit

But sometimes access doesn't shut down properly. The window closes but it is still running in the background. Also, the .ldb file is showing in the directory.

Does anyone know what causes that? Is there a better way to quit out of access?

David Pimental
(US, Oh)
 
How are ya dpimental . . .

Instead use:
Code:
[blue]      DoCmd.RunCommand acCmdExit[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
This can be caused by setting a ref to the db in code, and not releasing it. Although Access should release the refs when the code is finished, this doesn't always seem to happen. eg
Code:
function Something
Dim db as Database
    Set db = CurrentDb
    ....
    ....

    [green][b]Set db = Nothing[/b][/green]
End function
Note that the variable 'db' has been set to Nothing at the end of the code, so that it releases the reference.

HTH

Max Hugen
Australia
 
Thanks both of you. I will change the exit strategy. I will also check my vba code. I usually set created objects to nothing; but I will check.

David Pimental
(US, Oh)
 
I have made the changes you suggested and it is working better. But it seems that any time there is a debug error, it doesn't shut down correctly.

Is that a problem of not having sufficient error checking?

David Pimental
(US, Oh)
 
Most likely! If you are using 'standard' style error checking you will have both exit and error sections. Any refs you need to release should be in the exit section.

Then, if you have an error, the code would go to your error section, then 'resume' the exit, releasing any refs in the process. eg:
Code:
function MyFunction
On error goto err_MyFunction
Dim db as Database
    Set db = CurrentDb
    ....
    ....

exit_MyFunction:
    [green][b]Set db = Nothing[/b][/green]
    Exit Function
err_MyFunction:
    MsgBox Err & ": " & Err.Description
    Resume exit_MyFunction
End Function


Max Hugen
Australia
 
Be sure that all the Recordset objects are closed and released.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks to both of you. Now for a few quick questions.

1. Should I have error checking on all functions / procedures, or just those with objects or those expected to be problematic?

2. Should I only be concerned with releasing "objects", such as RecordSet Objects?



David Pimental
(US, Oh)
 
In regards to question 2 you should not have to explicitly release variables when they go out of scope;however, because of bugs in practice many people do. This seems to be the common practice to release the following:
1. It is a data access object ADO or DAO connection, recordset, command ...
2. It is a MS Application using late binding (Word, PP, Access ...)
3. When you specifically want to release memory or release objects in a particular order.

I would say definately when using the application object or working from one application with another application's objects.

In regards to 1 you should have for all. It is always the procedure that you expect not to be problematic that turns out being problematic. Regardless if you are using objects or not you are just as likely to throw an error. Now in truth I imagine most people do not put error checking in all procedures. There are applications out there that help to write error checking within your code.
 
Thanks for the clarification. It is very helpful.

I have to do some cleanup first; then I'll put the error checking in. Thanks again to all.

David Pimental
(US, Oh)
 
1. Yes, use error checking in all functions/procedures. Even 'simple' code could have typos etc. Once you have the error handling to your satisfaction, you can use copy/paste to add to other functions, and replace (Ctl+H) the function name as required.

2. Personally, every ref that I 'Set', I then release by setting the ref to nothing in the exit.

Max Hugen
Australia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top