Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / September 2007

Tip: Looking for answers? Try searching our database.

Close a Database with code from another database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
neshev - 01 Sep 2007 11:30 GMT
Hi Huys,
I need to close a database if it is open. This code needs to be on a
seperate database. I have an installer database that when prompted closes the
front end database, deletes the file and copies a new file in its place (new
version). The problem is that when I try to delete the file, it will now
allow me if it is still open. I tried the following code:

Set MyDB = OpenDatabase("C:\Inspect.mdb")

MyDB.Execute Exit

MyDB.Close
Set MyDB = Nothing

My code to execute the exit is incorrect, does anyone know how to quit the
other database? Thanks in advance

Neil
Larry Linson - 02 Sep 2007 03:31 GMT
> I need to close a database if it is open. This code needs to be on a
> seperate database. I have an installer database that when prompted closes
the
> front end database, deletes the file and copies a new file in its place
> (new
> version). The problem is that when I try to delete the file, it will now
> allow me if it is still open.

Put the cursor on Execute in the VBA code, press F1, and read.  Execute is
for running a Query... "Exit" is not a valid option.  So, no wonder that did
not work.

The following code works for me to Open, Close, and Delete a database,
whether or not the database is currently Open.

Private Sub cmdQuitRemote_Click()
Dim dbOther As Access.Application

' Set the dbOther object, either a new or existing instance
   Set dbOther = GetObject("C:\Data\Access\Access2003\CloseRemotely.MDB")
   Debug.Print dbOther.Name
   dbOther.Quit                    'Close the dbOther
   Set dbOther = Nothing
   Kill "C:\Data\Access\Access2003\CloseRemotely.MDB"

Exit_cmdQuitRemote_Click:
   Exit Sub
End Sub

Larry Linson
Microsoft Access MVP
neshev - 02 Sep 2007 10:30 GMT
Thanks for that Larry, great help.

>  > I need to close a database if it is open. This code needs to be on a
>  > seperate database. I have an installer database that when prompted closes
[quoted text clipped - 27 lines]
>  Larry Linson
>  Microsoft Access MVP
Larry Linson - 03 Sep 2007 06:03 GMT
> Thanks for that Larry, great help.

I'm glad I was able to assist.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.