ACC2: Use CurrentDB() Rather Than DBEngine(0)(0)

Last reviewed: June 8, 1997
Article ID: Q131881
The information in this article applies to:
  • Microsoft Access version 2.0

SYMPTOMS

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

The "CurrentDB Function" topic in the Microsoft Access Help system makes an incorrect recommendation in the "Note" section that reads as follows:

   Note The CurrentDB function is included in this version of Microsoft
   Access for compatibility with previous versions. It is recommended that
   you use the Databases(0) element of the Databases collection instead.
   For more information, see Examples of Converting Code to Version 2.0.

STATUS

This behavior no longer occurs in Microsoft Access version 7.0.

MORE INFORMATION

The correct recommendation is that you use the CurrentDB() function instead of DBEngine(0)(0) for the following reasons:

  • DBEngine(0)(0) is synonymous with the current database in Microsoft Access version 2.0. However, this behavior is subject to change in future versions.
  • CurrentDB()and DBEngine(0)(0) have slightly different behaviors. DBEngine(0)(0) returns a pointer to an object whereas CurrentDB() creates a new object. This means that when you have two functions that set database variables to DBEngine(0)(0), if the second function closes DBEngine(0)(0), both functions are affected. When you return to the first function, you may receive the following error message:

          Object is no longer valid.
    
  • DBEngine(0)(0) can sometimes reference the incorrect database. For example, you can set a database object to the current database using DBEngine(0)(0) in DB1.MDB, and then you can call a library database that sets DBEngine(0)(0) to a global variable. If you close DB1.MDB, open DB2.MDB, and reference DBEngine(0)(0).Name, you receive DB1.MDB instead of DB2.MDB.

REFERENCES

For more information about the CurrentDB() function, search for "CurrentDB," and then "CurrentDB Function (Data Access)" using the Microsoft Access Help menu.


Keywords : kbprg MdlDao
Version : 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbdocerr


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.