You can use Data Access Objects (DAO) properties, objects, and methods the same way you reference and use Microsoft Word properties, objects, and methods. After you establish a reference to the DAO object library, you can open databases, design and run queries to extract a set of records, and bring the results back to Word.
Referencing DAO
Before you can use DAO, you must establish a reference to the DAO object library. Use the following steps to establish a reference to the DAO object library.
If you don't see Microsoft DAO 3.6 Object Library in the Available References box, run Office Professional Setup to install the Data Access Objects for Visual Basic. The Microsoft DAO 3.6 Object Library is not included with the standalone version of Word or Microsoft Office 2000 Standard.
The following example opens the Northwind database and inserts the items from the Shippers table into the active document.
Set Db = OpenDatabase _
(Name:="C:\Microsoft Office\Office\" _
& "Samples\fpnwind.mdb")
Set Rs = Db.OpenRecordset(Name:="Shippers")
For I = 0 To Rs.RecordCount - 1
Selection.InsertAfter Text:=Rs.Fields(1).Value
Rs.MoveNext
Selection.Collapse Direction:=wdCollapseEnd
Selection.InsertParagraphAfter
Next I
Rs.Close
Db.Close
Use the OpenDatabase method to connect to a database and open it. After opening the database, use the OpenRecordset method to access a table or query for results. To navigate through the recordset, use the Move method. To find a specific record, use the Seek method. If you need only a subset of records instead of the entire recordset, use the CreateQueryDef method to design a customized query to select records that meet your criteria. When you finish working with a database, it's a good idea to close it using the Close method, to save memory.
Note For more information about a specific DAO object, method, or property, see Data Access Objects Help.