Close a Database with code from another database

G

Guest

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
 
L

Larry Linson

neshev said:
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
 
G

Guest

Thanks for that Larry, great help.

Larry Linson said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top