Chapter 5: Interacting with Data Using ADO and SQL


In this chapter, you turn your attention to one of the most important concepts in Access programming: working with data in databases. Data is, after all, at the heart of almost every application. Programmers typically write applications to enable users to interact with data in meaningful ways. You have probably created Access applications yourself that retrieve data using forms that are bound directly to tables.

This chapter expands your knowledge of working with data by covering the basics of retrieving and modifying data from VBA code using ActiveX Data Objects (ADO). You will create the same contact form in three different ways so that you can see the various approaches to interaction with the same underlying data source. I will also cover the basics of writing SQL statements to interact with the database. The chapter ends with a brief section on the ADOX object model that can be used to manage database objects such as tables, users, and groups.

Introduction to Data Access

ADO is an acronym for ActiveX Data Objects. DAO stands for Data Access Objects. Both ADO and DAO allow you to manipulate databases from your Access 2007 VBA code.

The prior editions of this book with Access 2002 and earlier covered DAO in detail. DAO has been around since the earliest versions of Access and has always been an excellent data access method for working with native Access data.

ADO is a better choice for building sophisticated, multiuser applications or applications that interact with databases other than Access. It appears that DAO is being phased out, and most books and other resources you find on the topic recommend that ADO be used for all new development. I agree with this recommendation and have, therefore, in both the prior 2003 edition of the book and now with this 2007 edition continued to focus the examples on ADO. If you are dealing with older Access applications that have DAO code, consult the 2002 or prior editions of this book for a comprehensive explanation of DAO, or the online help documentation built into Access and the VBA Editor.

Tip 

ADO should not be confused with ADO.NET. ADO.NET is a version of ADO that is designed to work with the Microsoft Visual Studio .NET development environment. Although ADO and ADO.NET have a lot of features in common, they are also different in numerous ways. In the future, it is possible that Microsoft will integrate the ADO.NET functionality into Microsoft Access to replace ADO, but such integration is not a certainty. Visual Studio Tools for Office (VSTO) uses ADO.NET. If you plan to use .NET in the future for your development or are already a .NET developer, then you should concentrate on ADO.NET.




Beginning Access 2007 VBA
Beginning Access 2007 VBA
ISBN: 0470046848
EAN: 2147483647
Year: 2004
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net