Using DAO from Microsoft Word
|Word Developer Reference|
You can use Data Access Objects (DAO) properties, objects, and methods the same way that you reference and use Microsoft Office 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.
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.
- Switch to the Microsoft Visual Basic Editor.
- On the Tools menu, click References.
- In the Available References box, select Microsoft DAO 3.6 Object Library.
The following example opens the Northwind database and inserts the items from the Shippers table into the active document.
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 is a good idea to close it using the Close method, to save memory.
For more information about a specific DAO object, method, or property, see the information about Data Access Objects on MSDN.