Writing Code in Access Projects

3 4

The Data Access Objects (DAO) object model is generally the best choice for writing code in Access databases when you're dealing with data in Access tables. This object model has developed over the years with Access, and it's the most efficient and powerful tool for working with Access data. However, you need the newer ADO object model when you're working with data in SQL Server tables. You can use both object models in the same project as long as you use the object library prefix to ensure that the object is linked to the correct object library, as shown in the following code segment:

 Dim dbs as DAO.Database Dim rstDAO as DAO.Recordset Dim rstADO as ADODB.Recordset 

Although each object model has some unique elements-for example, there's no Database object in the ADO object model, so you can omit the DAO prefix when you declare a Database variable-it's good policy to always use the object library prefixes so that you're reminded of what type of object you're working with. Using this type of convention also enables others to read and understand your code.

In a new Access 2000 or Access 2002 database, the ADO object library is selected by default but the DAO object library isn't. If you're using the DAO object library, you must set a reference to it by opening the References dialog box (choose Tools, References in the VBE window) and selecting Microsoft DAO 3.6 Object Library in the Available References list, as shown in Figure 19-43.

figure 19-43. you can select the dao object library reference in the references dialog box so that you can reference its components in code.

Figure 19-43. You can select the DAO object library reference in the References dialog box so that you can reference its components in code.



Microsoft Access Version 2002 Inside Out
Microsoft Access Version 2002 Inside Out (Inside Out (Microsoft))
ISBN: 0735612838
EAN: 2147483647
Year: 2005
Pages: 172
Authors: Helen Feddema

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