More portable DAO Recordset code between Access Versions
Jul 22 2008, 06:13 PM
From: Brisbane, Australia
G 'day all.
Two functionally equivalent pieces of code, but one has an advantage: -
Option Compare Text
Public Sub Case1()
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tblMyTable", dbOpenDynaset)
Do Until rst.EOF
Set rst = Nothing
Set dbs = Nothing
Public Sub Case2()
With CurrentDb.OpenRecordset("tblMyTable", 2)
Do Until .EOF
In case1 everything has been declared as DAO (something or other).
This incurs two penalties.
The first is obvious and minor, the code is longer.
The second is that it requires a reference to DAO.
In case2 the code is shorter and requires no reference to DAO.
It does not matter if references are or are not declared for DAO or ADO or at which priority they might occur.
It simply doesn't matter.
Please also note that DAO constants, such as dbOpenDynaset, should not be used but rather their numerical equivalent substituted.
What this boils down to is that, by writing more code to disambiguate the difference between DAO and ADO, our code has become dependent on references.
If we can avoid the disambiguation we also avoid reference problems and if we avoid reference problems our code becomes more portable.
|Go to Top · Lo-Fi Version||Time is now: 24th May 2013 - 09:20 PM|