Access.2007.VBA.Bibl..

(John Hannent) #1
You can’t exchange data between ADO and DAO recordsets, even when working in
databases with references set to both object models.

TABLE 5.7

ADO Equivalents of DAO Objects


DAO Object ADO Object Notes

DBEngine No equivalent Not needed
Workspace No equivalent Not needed
Database Connection
Recordset Recordset
Dynaset type Keyset cursor
Snapshot type Static cursor
Table type Keyset cursor with acCmdTableDirect option
Field Field Recordset fields only
QueryDef No direct equivalent, but can use the Command object
to get the same functionality
TableDef No equivalent

When using the DAO object model to work with Access data, the following code segment opens a
recordset based on a query in an external database:

Dim dbs as DAO.Database
Dim strDBName As String
Dim rst As DAO.Recordset

strDBName = “E:\Documents\Northwind.mdb”
Set dbs = OpenDatabase(Name:=strDBName)
Set rst = dbs.OpenRecordset(Name:=”qryCurrentOrders”, _
Type:=dbOpenDynaset)

This ADO code opens an equivalent recordset:

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strDBName As String
Dim strConnectString As String
Dim strQuery As String

TIPTIP


Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf