Applecore Pages on Microsoft Access

Is a Database already open?

If you wish to check whether a user already has a Database open on their computer, possibly the easiest way of doing this is to try to open the Database exclusively. Obviously, if the database is already open, then this will fail, and produce a trappable error:

Function fIsDatabaseRunning(strDBName As String) As Boolean
'   Function to check if a database is already running
'   Accepts:
'       The path and name of an Access database
'   Returns:
'       True if the database can't be opened (because it is already open)
'       False if the database can be opened (becuase it is not already open)

    On Error GoTo E_Handle
    fIsDatabaseRunning = True
    Dim db As Database
    Set db = DBEngine(0).OpenDatabase(strDBName, True)
    fIsDatabaseRunning = False
fExit:
    On Error Resume Next
    db.Close
    Set db = Nothing
    Exit Function
E_Handle:
    Select Case Err.Number
        Case 3356 ' Database already opened
        Case Else
            MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
    End Select
    Resume fExit
End Function

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:56:56