ACC2000: Cannot Check to See If Database Was Opened Exclusively

ID: Q210592


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.


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 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:


  4. 
    Option Explicit 
  5. Type the following procedure:


  6. The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you need to reference the Microsoft DAO 3.6 Object Library.


    
    Sub TestOpenDB()
      Dim db As DAO.Database
      Set db = OpenDatabase("C:\Program Files\Microsoft Office\Office\" & _
        "Samples\Northwind.mdb", False)
      db.Close
    End Sub 
  7. 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.

Additional query words: prb


Keywords          : kbprg kbdta AccCon PgmObj KbVBA 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: May 13, 1999