ACC1x: "Invalid Database Object" Error Message

Last reviewed: June 8, 1997
Article ID: Q94600
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1

SYMPTOMS

When you are trying to use a database object (database, QueryDef, table, dynaset, snapshot) within Access Basic, you may receive the following error message:

   Invalid Database Object.

CAUSE

The problem occurs if you are within a transaction, you call another function or procedure which dimensions the database, and then leave the function or procedure which implicitly closes the object that was opened within the transaction.

In this case Microsoft Access will try to close it and since it was opened within a transaction, Microsoft Access will roll back all levels of nested transactions.

If any other database objects were opened within the transaction, rolling back has the effect of closing them. This means that any references to an object opened within a transaction after another object was forced to be implicitly closed will result in the "Invalid database object" error message.

This problem will not occur if you always close database objects before they go out of scope. The problem only occurs if you let Microsoft Access implicitly close them.

RESOLUTION

  • You should always try to open database objects outside of transactions.
  • You should always explicitly close database objects.

STATUS

This behavior no longer occurs in Microsoft Access version 2.0.

MORE INFORMATION

Steps to Reproduce Behavior

Open the sample database NWIND.MDB and enter the following code fragment in a module to illustrate the problem:

   Function One ()
      Dim MyDB As Database, MyTable As Table

      Set MyDB = CurrentDB()
      BeginTrans
         Set MyTable = MyDB.OpenTable("Employees")
         X = Two()
         Debug.Print MyTable.RecordCount '"Invalid database object."
         MyTable.Close
      CommitTrans
      MyDB.Close
   End Function

   Function Two ()
      Dim MyDB2 As Database
      Set MyDB2 = CurrentDB()
   End Function

MyDB loses scope, implicitly rolls back and closes MyDB with the effect of also closing MyDB in the One() function.

To circumvent the problem, change the procedure Two to:

   Function Two()
      Dim MyDB2 as Database
      Set MyDB2 = CurrentDB()
      MyDB2.Close
   End Sub
 

	
	


Keywords : JetTrans kberrmsg kbprg MdlTran PgmObj
Version : 1.0 1.1
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : Info_Provided


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.