Access Cookbook - Ken Getz [9]
How Do I Use Data Access Objects (DAO) in New Databases?
By default, new databases that you create in Access 2000 and later assume that you'll want to use ActiveX Data Objects (ADO) rather than the older set of objects for accessing data, DAO. Many of the examples in this book take advantage of DAO, because it's simpler, more consistent with earlier programming techniques, and is in general just as efficient (or more efficient) than using ADO for programming against Access data (that is, data stored in an MDB or MDE file). Both ADO and DAO are simply ActiveX/COM components provided for you by Windows and Microsoft Office, and before you can use either, you must set a reference to the appropriate type library.
If you use the projects that come with this book, you'll find that the code already includes a reference to the necessary type library so that each example works. If you create your own projects that use the techniques you find here, you may need to set a reference to the DAO type library yourself. Follow these steps to set the reference:
Within the VBA code editor, select the Tools → References menu to display the References dialog box, shown in Figure P-9.
Figure P-9. Set a reference to the Microsoft DAO type library, which allows you to use DAO within applications in Access 2000 and later
Scroll down within the dialog box until you find the reference to Microsoft DAO, and select it.
Click OK to dismiss the dialog box.
You'll use this same technique to set a reference to any external component (including Word, Excel, PowerPoint, and Outlook, in Chapter 14), but you'll need to set a reference to DAO as shown here for many of the samples in other chapters.
TIP
You don't need to explicitly set a reference to DAO within Access 97 or earlier versions. The change, in which the use of DAO became optional, happened in Access 2000.
Conventions Used in This Book
Throughout this book, we've used the following typographic conventions:
Constant width
Constant width in body text indicates a language construct, such as the name of a stored procedure, a SQL statement, a VBA statement, an enumeration, an intrinsic or user-defined constant, a structure (i.e., a user-defined type), or an expression (e.g., dblElapTime = Timer - dblStartTime). Code fragments and code examples appear exclusively in constant-width text. In syntax statements and prototypes, text set in constant width indicates such language elements as the function or procedure name and any invariable elements required by the syntax.
Constant width italic
Constant width italic is used in body text for variables and parameter names. In syntax statements or prototypes, constant width italic indicates replaceable parameters.
Italic
Italicized words in the text indicate intrinsic or user-defined function and procedure names. Example URLs are also italicized, as are many system elements, such as paths and filenames. Finally, italics are used the first time a new term appears.
TIP
This icon indicates a tip, suggestion, or general note.
WARNING
This icon indicates a warning or caution.
Comments and Questions
Please address comments and questions concerning this book to the publisher:
O'Reilly & Associates, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international/local)
(707) 829-0104 (fax)
There is a web page for this book, which lists errata, examples, or any additional information. You can access this page at:
http://www.oreilly.com/catalog/accesscook/
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about books, conferences, Resource Centers, and the O'Reilly Network, see the O'Reilly web site at:
http://www.oreilly.com
Acknowledgments
No book is written without some help from outside sources, and this one is no exception. In this case, we had special help: Mary Chipman did the bulk of the conversion work for the previous edition, making sure each topic