Converting DAO Code to ADO

Microsoft Access Visual Basic

Converting DAO Code to ADO

   

Microsoft Access includes ActiveX Data Objects (ADO) 2.5 as the default data access library. Although Data Access Objects (DAO) 3.6 is included it is not referenced by default. To aid in converting code to the newer ADO standard the following information is provided.

Note   Versions of the DAO library prior to 3.6 are no longer provided or supported in Microsoft Access 2002

DAO to ADO object Map

DAO ADO(ADODB) Note
DBEngine None  
Workspace None  
Database Connection  
Recordset Recordset  
Dynaset-Type Keyset Retrieves a set of pointers to the records in the recordset
Snapshot-Type Static Both retrieve full records but a Static recordset can be updated.
Table-Type Keyset with adCmdTableDirect Option  
Field Field When referred to in a recordset
DAO ADO
Open a Recordset
Dim db as Database
Dim rs as DAO.Recordset
Set db = CurrentDB()
Set rs = db.OpenRecordset(“Employees”)
Dim rs as New ADODB.Recordset
rs.Open “Employees”, CurrentProject.Connection, adOpenKeySet, adLockOptimistic
Edit a Recordset
rs.Edit
rs(“TextFieldName”) = “NewValue”
rs.Update
rs(“TextFieldName”) = “NewValue”
rs.Update 

Note   Moving focus from current record via MoveNext, MoveLast, MoveFirst, MovePrevious without first using the CancelUpdate method will implicitly execute the Update method.