Author: Calvin Smith
http://www.CalvinSmithSoftware.com/codedisk/sneakpeek.htm

The following code will allow a developer to programmatically
determine if a database is opened exclusively.


Function IsOpenedExclusively(strAnyDatabaseFile As String) As Boolean

' ---------------------------------------------------------------------------------
' Author: Calvin Smith - JobForCalvin@Yahoo.com
' Environment(s): MS Access (32-bit) / Visual Basic (32-bit)
' ---------------------------------------------------------------------------------
'
'   *****************************************
'   * Courtesy code from my CodeDisk© product
'   *****************************************
   '
   ' ----------------------------------------------------------------------------
   ' Purpose: Example of how to check for an exclusively opened database
   '
   ' Accepts: strAnyDatabaseFile as the valid path and MDB file name
   '
   ' Returns: True if opened exclusively, False otherwise
   '
   ' Example: bRetVal = IsOpenedExclusively("C:\CodeDisk\CodeDisk.mdb")
   ' ----------------------------------------------------------------------------
   '
On Error Resume Next

          '
          ' Below, if the OpenDatabase method failed with error 3045,
          ' it is already opened exclusively in Access 97
          '

          Dim dbe As New DBEngine

          Dim dbExternalMDB As Database

          Set dbe = New PrivDBEngine

          Set dbExternalMDB = dbe.OpenDatabase(strAnyDatabaseFile)

          IsOpenedExclusively = (Err.Number = 3045)

          ' Close the database pointer if opened
          If Not (dbExternalMDB Is Nothing) Then dbExternalMDB.Close

          Set dbe = Nothing

End Function