DAO and workspace

lmcc007

Registered User.
Local time
Today, 11:42
Joined
Nov 10, 2007
Messages
635
I am trying to understand some code I keep seeing, for example:

Dim dbMyDB As DAO.Database
Set dbMyDB = DBEngine.Workspace(0).Databases(0)
I found explanations for DAO and workspace, but it does not make sense to me.

I need non-technical explanations or explanations explained simple enough that a dummy can understand it. For some reason I can't comprehend why DAO and workspace is needed or what it is used for in Access.

Any simple explanations and/or examples are appreciated.

Thanks!
 
You almost never need to use workspaces. On thing you might use at the workspace level are transactions, where you can cache multiple and/or dependent data updates, and ensure they all succeed or they all fail. This can also be faster than doing mutiple disk writes, since in a transaction you can cache them and commit them to disk all at the same time.
Also, you don't need to use this DBEngine.Workspaces(0)(0) syntax anymore. Since Access 97, I think, there is the Access.Application.CurrentDb method which returns a reference to the default database in the default workspace.
Code:
dim dbs as dao.database
set dbs = currentdb
 
Thanks, but I am trying to learn programming--VB. That was just some code I saw and was trying to understand what it meant?

What is DAO (Data Access Objects) and why I need to use it? I need to know why I am using it, etc.
 
You could think of DAO as the client library to Jet (the database engine). It provides you an high-level interface that makes it simple to interact with the data stored in Jet.

It's not the only option; there's also ODBC, ADO, and possibly lower-level interfaces via the Jet's .dll files. However, DAO is developed for specifically Jet so it's usually the most efficient route.
 
A "high-level interface," is that like a template. Like in Word I use templates to create documents. The templates has the formatting, font, and size set.

What is Jet?
 
A city has different buildings, like a planetarium, a subway station, a stadium, a hospital. Each of these buildings is designed for a specific activity or has a specific purpose.
Likewise there is a network of roads and rails and common areas that permit communication and transportation between these fixtures.

A programming environment is similar in some ways to this city. There are object models--analogous to buildings--that you can leverage for specific tasks. DAO, for instance, provides a set of tools to work with data. DAO leverages the distinct language SQL to communicate with the Microsoft Jet Database Engine which handles requests for data from Access tables. DAO, SQL, Jet, Access, each of these are distinct 'buildings' that interoperate to enable you to perform considerable tricks and treats with data.
And binding them together in MS Office is VBA, or Visual Basic for Applications. This is like your network of roads and rails--or programming--that you can use to move stuff to and from the different object models for processing.

So Access provides the Button Object and the Click Event. You can handle those in your VBA code and run the DAO.Database.Execute method--passing in the appropriate SQL--and delete a record from a Jet table.

"High Level?" High level of abstraction. You don't have to concern yourself with the specific nuts and bolts of HOW things get done. You write code like...
Code:
CurrentDb.Execute "DELETE FROM table WHERE id = 12", dbFailOnError
...and thousands of "low-level" events--down to zeros and ones--occur to remove that record from that table.
 
Thanks lagbolt,

I am not understanding it, but I will reread the above again. I am looking at the meaning for Jet in Wikipedia now. And I just found something on Allen Browne's site re DAO.
 

Users who are viewing this thread

Back
Top Bottom