ACC2000: Cannot Check to See If Database Was Opened Exclusively (210592)



The information in this article applies to:

  • Microsoft Access 2000

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.

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 on the File menu.
  2. 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.
  3. Create a module and type the following line in the Declarations section if it is not already there:
    Option Explicit
    					
  4. 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
    					
  5. 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.

REFERENCES

For more information about the OpenDatabase method, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type OpenDatabase method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MajorLast Reviewed:12/12/2002
Keywords:kbdta kbprb kbProgramming KbVBA KB210592