Microsoft KB Archive/210592

= ACC2000: Cannot Check to See If Database Was Opened Exclusively =

Article ID: 210592

Article Last Modified on 12/12/2002

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210592



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



SYMPTOMS
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.



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



Steps to Reproduce Behavior
The following Visual Basic procedure successfully opens the current database, even if the current database has been opened exclusively.  Start Microsoft Access and click Open on the File menu. In the Open box, select the sample database Northwind.mdb. Click the arrow to the right of the Open button, and then click Open Exclusive.  Create a module and type the following line in the Declarations section if it is not already there: Option Explicit   Type the following procedure:NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

Sub TestOpenDB Dim db As DAO.Database Set db = OpenDatabase("C:\Program Files\Microsoft Office\Office\" & _   "Samples\Northwind.mdb", False) db.Close End Sub   To test this function, type the following line in the Immediate window, and then press ENTER.

TestOpenDB

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

<div class="references_section">