Microsoft KB Archive/94035

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

Article ID: 94035

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q94035



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.

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 &quot;Building Applications with Microsoft Access&quot; 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 &quot;Introduction to Programming&quot; manual in Microsoft Access version 1.x or the &quot;Building Applications&quot; 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 ' '; 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.



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 Database on the File menu. 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).  Create a module and type the following line in the Declarations section: Option Explicit   Type the following procedure.

NOTE: In the following example, type the full path to the Northwind sample database in the OpenDatabase method. For example, &quot;C:\Access\Sampapps\Nwind.mdb&quot; or &quot;C:\Msoffice\Access\Samples\Northwind.mdb.&quot; Sub TestOpenDB Dim db As Database Set db = OpenDatabase(&quot;Northwind.mdb&quot;, False) db.Close End Sub  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.</li></ol>

<div class="references_section">