USING DATA ACCESS OBJECTS VERSUS ACTIVEX DATA OBJECTS

Although the choice of using DAO versus ADO is fast becoming a moot point because Microsoft is aiming us that way, it's a very real one for Access 2000.

As mentioned at the beginning of this chapter, DAO has been around for quite a few versions of Access and has pretty well been the standard for database manipulation with Jet from VB and all Office products.

Then along comes ADO. ADO has come on the scene because DAO was written and optimized mainly for Jet. The idea is that with the way the world is going with the Internet and multiple data sources, the belief was that an easier, more generic way to access that data was needed—hence, ADO.

Note

In Access 2000, not all functionality is provided in ADO to replace DAO. For example, when using objects and methods such as Me!subForm.Requery, the DAO object model is still used under the covers.


Where using DAO requires a reference to one object model, ADO requires three to cover most of the same ground. You can see this in Figure 3.3, by choosing References from the Tools menu in the VBE.

Figure 3.3. When converting to ADO from DAO, you can have code that references both in the same application.


As just mentioned, DAO uses one library, Microsoft DAO 3.6 Object Library, whereas ADO uses three (see Table 3.2). Chapter 6, “Introducing ActiveX Data Objects,” discusses each library in more detail.

Table 3.2. ADO Libraries and Their Purpose
Library Purpose
Microsoft ActiveX Objects 2.1 Library Data manipulation
Microsoft ADO Ext. 2.1 for DDL and Security Data definition and security
Microsoft Jet and Replication Objects 2.1 Replication

Tip

Whichever version you want to have as the default, place it before the other. For example, if I wanted to use ADO recordsets as the default, I would move its library up before DAO's. This is important because when you Dim something as a recordset, you want to get the right type. Otherwise, errors can occur.

You can also use the Library.ClassName syntax:

Dim rstX As ADODB.Recordset
Dim dynY As DAO.Recordset


Note

In revising this book for Access 2000, the decision of how to cover DAO/ADO was the most difficult choice as well as the most discussed aspect. Generally, I wouldn't recommend solving the problem as I did here. This book is trying to give you as much information as possible; this isn't a project in which the simpler you can make it, the better.

It was decided that when heavy-duty VBA was used for manipulating data in code, the example—and sometimes the whole chapter—would be presented by using DAO and ADO. In this way, you get not only examples using whichever method you wanted to use, but also have examples of converting from one data access method to the other.


Just because you're using SQL Server as a back end doesn't automatically mean that you should use an ADP with ADO. There are still good reasons to use Jet-linked table SQL Server applications in many situations:

  • Your application requires storage on the front end, such as user preferences or SQL strings in tables. In an ADP, you have to use the Registry or file system for such storage.

  • Your application requires users to be able to create and store ad hoc queries, and you can't or don't want to give the users permissions to create server objects.

  • Linked-table applications are still better at joining information from heterogeneous data sources (ISAM stuff).

Also, as I've discovered, ADO in Access 2000 is just plain harder to use than DAO, especially in the areas of using DDL and parameterized queries (stored procedures). For example, to get an updatable recordset in ADO, by default you can't omit parameters to the call opening the recordset. (I still forget this occasionally.)

The bottom line is that DAO is fading in future versions of Microsoft products. It probably will be supported in a couple more versions, but even DAO 3.6 hasn't had any enhancements made.

If you're using DAO now, start looking at converting your applications over. If the application doesn't have major changes in store, however, I would hold off.

If you're just starting to develop applications in VBA and Office products, or even have to start a new application, jump on the ADO bandwagon. Just know that there are some issues you might have to work around.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.59.129