Открыта ли БД монопольно
Is database open exclusively
Applies to: Access 97
Function IsDbOpenedExclusively(Optional strDbPath As String = "") As Boolean
' This function uses the unsupported PrivDBEngine object to check
' whether a database is open exclusively. This is useful when you
' want to check whether the current database is open exclusively,
' since you can open the current database exclusively any number
' of times with the same DBEngine object.
'
' Arguments:
' strDbPath: The path to the database you want to check.
' If left out, the current database is used.
' Returns:
' A Boolean value indicating whether the database is opened exclusively.
On Error Resume Next
Dim dbe As PrivDBEngine
Dim wrk As Workspace
Dim dbs As Database
Const conFileInUse As Integer = 3045
Const conDBOpenedExclusively As Integer = 3356
If Len(strDbPath) = 0 Then strDbPath = CurrentDb.Name
' Return reference to private DBEngine object.
Set dbe = New PrivDBEngine
' Return reference to default workspace.
Set wrk = dbe.Workspaces(0)
' Attempt to open database.
Set dbs = wrk.OpenDatabase(strDbPath)
' If reference to database isn't returned, check error.
If dbs Is Nothing Then
' If error indicates database is open exclusively, return True.
If (Err = conFileInUse Or Err = conDBOpenedExclusively) Then
IsDbOpenedExclusively = True
' If unanticipated error occurs, display message.
Else
MsgBox "Error: " & Err & ": " & vbCrLf & Err.Description
End If
' If reference to database is returned, it must not be opened
' exclusively by any other user.
Else
IsDbOpenedExclusively = False
dbs.Close
Set dbs = Nothing
End If
End Function
From Andy Baron , Entry Date 24.09.1999
Written and designed by |
![]() |