instance 0 of DBEngine() and Workspace 0 of Worspaces() is CurrentDB
Main Topics
Browse All TopicsI've never quite understood what it is I'm really asking for with DBEngine(0)(0).TableDefs, and how and why it differs from CurrentDb.TableDefs. I just know that it needs to be used sometimes. Can someone elaborate on the differences a little?
In particular, I have encountered this problem today: I have a routine that outputs the properties of each table at the field level. If I make changes to a table, my routine does not see them. I need to close the database and reopen it before my routine, which uses DBEngine(0)(0).TableDefs, can see them. Why?
Mike
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
They are not exactly the same. Take a look here for an informed and complete explanation by guru Michael Kaplan...
http://groups.goo
BTW,
--
Graham Mandeno [Access MVP]
First: DBEngine(0)(0) is shorthand for this:
DBEngine.Workspaces(0)
So when you do this:
DBEngine(0)(0).TableDefs
You're asking for the Tabledefs Collection from the defalt Database of the default Workspace. Access is built using different collections, of course, and the top "level" in this case is the DBEngine. The DBEngine contains one or more Workspaces (generally only one, unless you add more), and the Workspaces collection contains several other collections (like Databases), and the Database collection cointains several collections (like TableDefs).
Currentdb is, basically, shorthand for DBEngine(0)(0).
In regards to the difference, this is from here: http://msdn.microsoft.com/
In previous versions of Microsoft Access, you may have used the syntax
DBEngine.Workspaces(0).Dat
or
DBEngine(0)(0)
to return a pointer to the current database. In Microsoft Access 2000, you should use the CurrentDb method instead. The CurrentDb method creates another instance of the current database, while the Visual Basic for Applications DBEngine(0)(0)syntax refers to the open copy of the current database. The CurrentDb method enables you to create more than one variable of type Database that refers to the current database. Microsoft Access still supports the Visual Basic for Applications DBEngine(0)(0)syntax, but you should consider making this modification to your code in order to avoid possible conflicts in a multiuser database.
<end paste>
DBEngine(0)(0) is much faster than Currentdb (about 5000 time faster). I've never timed it myself, but I've seen the results of many such tests on the internet, and I'd believe it.
According to Micheal Kaplan, one benefit CurrentDB has over DBEngine(0)(0) is that all collections will be always up to date - why this is I don't know, and Microsoft ain't telling, but if Kaplan says it about Access, you can go to the grave with it. If that's so then you've got your answer - when you're dealing with collections, and you want them to be up to date, use CurrentDB.
BTW, some of the above came from the link that Graham gave above. I've summarized, as that entire thread is a beast to read through - but very, very informative!
"when you're dealing with collections, and you want them to be up to date, use CurrentDB"
Or ... Use the Refresh Method on
DBEngine(0)(0).TableDefs,
>> DBEngine(0)(0).TableDefs.R
What it really comes down to is ... The TableDefs Collection on the DBEngine object is *not* automatically refreshed when you "If I make changes to a table", whereas the TableDefs Collection off of CurrentDB is.
More importantly (and as denoted above) ... right from the A2003 Help File on the CurrentDB Method:
"Note In previous versions of Microsoft Access, you may have used the syntax DBEngine.Workspaces(0).Dat
"DBEngine(0)(0) is much faster than Currentdb (about 5000 time faster)."
This would mainly apply if these we being used in a repetitive loop. And the only reason DBEngine would be faster ... from the Microsoft Jet Database Engine Programmers Guide 2nd Edition is ...
"The CurrentDB function differs from the DBEnigne(0)(0) syntax in that it creates another instance of the current database and returns a reference to that instance, and it refreshes all the collections in the current database. On the other hand, the DBEngine(0)(0) syntax doesn't refresh any collections, so it may ... perform faster"
Another way to state what CurrentDB is: It's the instance of Access that is opened in the Access User Interface.
I'm noting that most of what I've said has been stated one way or another above, but I tried to put a slightly different perspective on it.
mx
mx
And here is a good related read on the subject ... especially noting the comments of Leigh Purvis and Harfang (Marcus Fisher):
http://www.experts-exchang
mx
In the end, so long as you know the strengths and weaknesses of the two, you can use them interchangeably. For my money CurrentDB is the right choice, but you may have valid reasons for using DBEngine(0)(0). In the link provided by Graham, Kaplan uses a Property to get a handle on the current database (in this case it returns CurrentDB), and as I've stated before if he says that's the way to do it, then that's the way to do it ;).
I see that this is closed, so I can post without it being "piling on" :-)
Another forum's thread on somewhat related subject:
When to use CurrentDb and when to set a variable
Worth a read perhaps. In part, it continues on from that discussion of Markus and I. (Except with Brent this time).
The fundamental issue does resolve down to Scott's comment:
"In the end, so long as you know the strengths and weaknesses of the two, you can use them interchangeably"
You just have to get to that point of understanding.
DBEngine(0)(0) could potentially point to the wrong database. That's pretty disastrous as errors go. ;-)
It's a pretty unlikely scenario for many apps - but possible.
As mentioned - if you're in a loop then there's no way you should be using CurrentDb with each iteration, but a database variable assigned to the current database instead. (Similar to Michka's persistently returned property reference if you wish). Otherwise the difference becomes near negligible for that single assignment.
Cheers.
Business Accounts
Answer for Membership
by: GRayLPosted on 2009-10-06 at 17:10:56ID: 25511229
There is no difference. DBEngine(0)(0).TableDefs is the same as CurrentDb.TableDefs.
ie.
DBEngine(0)(0) is the same as CurrentDB