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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell if an Access database open

Status
Not open for further replies.

jopaumier

Programmer
Mar 15, 2002
97
0
0
US
I am using DAO to create a new (temporary) Access database with several tables whenever my program runs. Before creating the mdb, I check to be sure the database does not already exist using the file system object. If the mdb exists, I delete it (I want to absolutely certain I populate an empty database). How can I check to be sure the database that I want to delete is not open? I am checking for the existence of the ldb file, but it seems that there must be a better way.

Jim
 
...you can use the GetObject method like this:

Dim myAcc As Access.Application
Dim dbName As String

On Error Resume Next

dbName = "Test.mdb"
Set myAcc = GetObject(, "Access.Application")

Debug.Print myAcc.CurrentDb.Name
If Err.Number <> 0 Then
Debug.Print &quot;Not Running&quot;
Err.Clear
Else
If InStr(myAcc.CurrentDb.Name, dbName) Then
Debug.Print &quot;Running&quot;
Else
Debug.Print &quot;Not Running&quot;
End If
End If

Have Fun!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top