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

Technique to figure out if a database is open

Status
Not open for further replies.

Knicks

Technical User
Apr 1, 2002
383
US
I am working on a routine to Compact and Repair many databases that I will list in a table of a maintenance database. I am trying to figure out the easiest way to determine if a database is open.

One technique would be to compare a database file against its corresponding LDB locking file if its open. I would use Dir() function and parsing.

Lets say I have a database:

\\myserver\health\disease.mdb

then if it was open there would be

\\myserver\health\disease.ldb

How could I create a parsing statemnent to compare just the file name and disregard anything prior to the slashes and the extensions? I would be doing this with many different directories so the folders,slashes, and database name would change.

Is there an easier way from an external database to determine if a database is open?
 
Something like this would do what you describe:

Code:
Public Function IsOpen(ByVal strFilePath As String) As Boolean
    Dim strLDB As String

    strLDB = Left$(strFilePath, Len(strFilePath) - 3) & "ldb"
    
    If Dir(strLDB) <> "" Then
        IsOpen = True
    Else
        IsOpen = False
    End If
End Function

You need to pass the function a parameter containing the full file path and file name.

Of course this won't work if the database file is opened exclusively...

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top