ACC: Cannot Check to See If Database Was Opened Exclusively

ID: Q94035

The information in this article applies to:

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

In a multiuser environment, you cannot use the OpenDatabase method to find out if the current database was opened exclusively. If you try to open the current database with the OpenDatabase method in Visual Basic for Applications and the current database was originally opened exclusively, the database opens and no error is returned.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.

CAUSE

Microsoft Access ignores the option flags for all opens except the first for a given window's task, so a system administrator cannot use this to test whether a database has been opened exclusively. The technique does not work because Microsoft Access does not check the option flags.

RESOLUTION

Currently there is no workaround in Microsoft Access version 7.0 or earlier.

In Microsoft Access 97, you receive a trappable error:

   Run-time error 3045:
   Couldn't use '<filename>'; file already in use.

However, if you run any Visual Basic procedure that uses the CurrentDB() function or the DBEngine object before you execute the OpenDatabase method, the error does not appear.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

The following Visual Basic procedure successfully opens the current database, even if the current database has been opened exclusively.

1. Start Microsoft Access and click Open Database on the File menu.

2. Open the sample database Northwind.mdb (or NWIND.MDB in versions 1.x

   and 2.0). Click the Exclusive option in the Open dialog box (or Open
   Database dialog box in versions 1.x and 2.0).

3. Create a module and type the following line in the Declarations
   section:

      Option Explicit

4. Type the following procedure:

   NOTE: In the following example, type the full path to the Northwind
   sample database in the OpenDatabase method. For example,
   "C:\Access\Sampapps\Nwind.mdb" or
   "C:\Msoffice\Access\Samples\Northwind.mdb."

      Sub TestOpenDB()
         Dim db As Database
         Set db = OpenDatabase("Northwind.mdb", False)
         db.Close
      End Sub

5. To test this function, type the following line in the Debug window,
   and then press ENTER.

      TestOpenDB

   Note that you do not receive an error message that the database is
   already opened exclusively.

REFERENCES

For more information about the OpenDatabase method, search the Help Index for "OpenDatabase method."

Additional query words:

Keywords          : kbprg PgmObj 
Version           : 1.0 1.1 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb

Last Reviewed: November 21, 1998