Recordset vs. DAO.Recordset

Bilbo_Baggins_Esq

Registered User.
Local time
Today, 01:50
Joined
Jul 5, 2007
Messages
586
We have an automated tool to programmatically convert older files to newer formats.
Among other things, the tool reads the VBA for various potential errors and deprecated methods, constants, etc.

Bear in mind, all of these files with code are, in theory, fully functional in the older environment (XP w/2k3) when they are submitted.

Where possible, the automated tool performs some updates to the code.

One of the items it clearly does not like how our users have written them is recordsets.
For example:
Dim rs As Recordset

The above line of code gets changed to:
Dim rs As DAO.Recordset

After the automated tool completes the processes for a file, it generates a list of changes and suggestions (for items it could not change).
We provide that information back to the submitter in the form of a workbook.

On the lines where it details changes made for “Recordset”, it adds these comments:
Error Name: DAO Syntax Errors
Error Description: Unless existing DAO references are declared exclusively it is possible that run time errors can occur. Added DAO to the recordset declaration

I have used the same exact methodology as shown in the pre-edited example for years and do not recall ever encountering any errors because of that syntax.
We can turn this feature off, but before I do, I bring this question to the masters here.

Can anybody think of potential run-time errors that could result in an otherwise functional database directly attributable to failing to designate “DAO.recordset”?

Thanks in advance!
 
Can anybody think of potential run-time errors that could result in an otherwise functional database directly attributable to failing to designate “DAO.recordset”?

You left out the essential bit, which is "... after update to a newer version". And the answer is yes, it can cause runtime errors, because DAO disambiguates a declaration that on occasion might be taken as meaning ADO. That depends on the defualt sequence of references whcih did change at some stage (do not recall which version).
 
You absolutely should have it prefixed with DAO, use. Recordset is also an object in ADO, so if you had a library reference to ADO and it happened to be above DAO in the reference list, you'd have total chaos.

Sure it may have worked in previous versions ... And it may work in later versions too. You can get a lot of poor code to work - but the best practice is to prefix it with the library. Avoid ambiguity, even if you have it working in certain contexts.

If you have a reference checked to Excel, you might be able to get away with:
Dim wb as Workbook

But even if you could, you shouldn't. People get so used to Recordset they think it's part of Access. It isn't - it's part of DAO (and ADO).
 

Users who are viewing this thread

Back
Top Bottom