ACC1x: "Invalid Database Object" Error MessageLast reviewed: June 8, 1997Article ID: Q94600 |
The information in this article applies to:
SYMPTOMSWhen 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. CAUSEThe 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
STATUSThis behavior no longer occurs in Microsoft Access version 2.0.
MORE INFORMATION
Steps to Reproduce BehaviorOpen 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |