Close a Database Using VBA

TheSearcher

Registered User.
Local time
Today, 11:52
Joined
Jul 21, 2011
Messages
392
Hello,
I'm trying to improve performance of a split database by incorporating code that opens the back end when the user logs on. I have a procedure called OpenDB that works fine. The code is simple. It is:

Dim db1 As DAO.Database
Set db1 = DAO.OpenDatabase("L:\MyDatabase.accdb", False, False, "MS Access;PWD=MyPassword")

Obviously, I would want to close the back end when the user exits the program using another procedure called CloseDB. I'm having problems with the syntax. How can I reference the database that I want to close?

Dim db1 As DAO.Database
'*** Code to reference database here
db1.Close
Set db1 = Nothing

Thanks in advance for your help!
TS
 
you do not need to do this manually.the backend will manage itself automatically

just watch the .ldb file for the backend delete itself when you log out of the front end (and therefore no longer use the backend)

a database with no .ldb file IS closed
 
Thanks a lot Gemma. It makes sense.
 
Hi,

Just thought I add my observation on this, if you have a front end that is linked to your backend via the tables in it, then you don't need to open the backend database progammatically because when you opened up the linked table the backend DB is automatically opened also.

So for instance if you have a form which is based on a table that has a link to the backend db and you open that form and do some work, then the backend db will automatically open so that any changes you make to that table which is linked to the back end can take effect.

The same applies if you have a query that is based on a table that has a link to the backend.

This is assuming that the table resides in the backend db and is linked to the frontend db and not the other way around.

Regards
 
Hi JohnLee and thanks for your response. I understand what you say and agree with you. However, in trying to enhance the performance of my application I came across two articles that highly recommend using the technique that I described. The first is: https://www.fmsinc.com/MicrosoftAccess/Performance/LinkedDatabase.html and the second is http://support.microsoft.com/default.aspx?scid=kb;EN-US;209953. I'm not sure that I understand the reasoning but these are two reputable sites. Any thoughts you have on the articles would be appreciated.
Thanks,
TS
 

Users who are viewing this thread

Back
Top Bottom