Whats the difference between DBEngine(0)(0) and CurrentDb


J

John T Ingato

What is the difference?

Does "DbEngine(0)(0)" not return a database object, just as CurrentDb does?

I have run an action query with:

DbEngine(0)(0).Execute AppendSQL
lngItemsAdded = DbEngine(0)(0).RecordsAffected

The append query works fine and recordsAffected returns the number of items
added. But when I rewrite the code as follow:

CurrentDb.Execute AppendSQL
lngItemsAdded = CurrentDb.RecordsAffected

The append query works fine, but RecordsAffected = 0
 
Ad

Advertisements

M

Marshall Barton

John said:
What is the difference?

Does "DbEngine(0)(0)" not return a database object, just as CurrentDb does?

I have run an action query with:

DbEngine(0)(0).Execute AppendSQL
lngItemsAdded = DbEngine(0)(0).RecordsAffected

The append query works fine and recordsAffected returns the number of items
added. But when I rewrite the code as follow:

CurrentDb.Execute AppendSQL
lngItemsAdded = CurrentDb.RecordsAffected

The append query works fine, but RecordsAffected = 0


DbEngine(0)(0) is the first database in the first workspace.
While most of the time that is the current db, it is not
guaranteed.

CurrentDb() is a function (the paranthesis are optional when
the function has no arguments) that returns a database
object for the current db, The function also make sure that
all collections have been refreshed (DbEngine(0)(0) does
not). Unless you realy know what you're doing under all
your possible execution scenarios, I strongly recommend
using CurretDb().

The problem with your code as written is that you are using
two different instances of a database object. To put it
succinctly:
CurrentDb() Is CurrentDb()
is always False.

Change the code to:

Dim db As DAO.Database
Set db = CurrentDb()
db.Execute AppendSQL
lngItemsAdded = db.RecordsAffected
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top