7.1. Ambiguous References

In versions prior to Access 2000, the DAO object library was selected by default when a new database was created, allowing developers to write code using DAO.

Access 2000 selected the ADO object library by default (supposedly expecting developers to write using ADO), but this move generated much heartache, because Microsoft didn't adequately advise anyone of the change. Since average Access developers didn't know the difference between the two object models, the first they learned about it was when their applications started generating errors in code that had previously worked.

By the time Microsoft realized the ramifications, Access 2002 was already in beta, and the ADO preselection remained, but the issue is resolved in Access 2003. In Access 2003, both object libraries are preselected.

That being the case, writing unambiguous code has never been more important, because, for the first time, the very real possibility exists that a novice developer could inadvertently write ambiguous code. So what does this all mean? Consider the following:

Dim db As Database
Dim rs As Recordset

Nothing terribly strange there, except for two things: First, only DAO has a Database object—ADO has none. Second, DAO and ADO both have Recordset objects. If both DAO and ADO object libraries are selected, to which object model does the above recordset declaration refer?

If you have only one library referenced, Access chooses that one, but if you have two, Access encounters the ...

Get Access 2003 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.