> 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.