ACC1x: "Invalid Database Object" Error Message
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 : kberrmsg kbprg MdlTran PgmObj
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbprb