You may also want to determine whether your own code is able to open a database exclusively. This information can be helpful with many operations, such as:
In addition, the user that is currently logged on may not have permission to open the database exclusively.
See Also For more information about Design Master replicas, see Chapter 7, “Database Replication.” For more information about user permissions, see Chapter 10, “Managing Security.”
To determine whether you can open a database exclusively, use the PrivDBEngine object in code that is similar to the IsDbOpenedExclusively function shown in the preceding example:
Function CanOpenDbExclusively(strDbPath As String) As Boolean On Error Resume Next Dim dbe As PrivDBEngine Dim wrk As Workspace Dim dbs As Database Const conFileInUse = 3045 Const conDBOpenedExclusively = 3356 Set dbe = New PrivDBEngine Set wrk = dbe.Workspaces(0) Set dbs = wrk.OpenDatabase(strDbPath, True) If dbs Is Nothing Then ' If error is unanticipated, display message. If (Err = conFileInUse Or Err = conDBOpenedExclusively) Then ' If database cannot be opened exclusively, return False. CanOpenDbExclusively = False Else MsgBox "Error: " & Err & ": " & vbCrLf & Err.Description End If Else ' If database can be opened exclusively, return True. CanOpenDbExclusively = True dbs.Close End If End Function
This function returns True if you can open the database exclusively.