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



The information in this article applies to:

  • Microsoft Access 2.0

This article was previously published under Q131881
Moderate: Requires basic macro, coding, and interoperability skills.

SYMPTOMS

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.

Modification Type:MajorLast Reviewed:7/5/2002
Keywords:kbProgramming KB131881