Is it improper to use DAO with RecordsetClone?
For example:
Dim rs as DAO.Recordset
Set rs = .RecordsetClone
Or should it be
Dim rs as Recordset
Set rs = .RecordsetClone
Is there a difference?
Why would you ever bother with that? I see a lot of people posting
navigation code like this:
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[criteria]"
If rs.NoMatch Then
MsgBox "Not Found!"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
It's far, far easier to do this:
With Me.RecordsetClone
.FindFirst "[criteria]"
If .NoMatch Then
MsgBox "Not Found!"
Else
Me.Bookmark = .Bookmark
End If
End With
The RecordsetClone already exists. There is no reason not to use it
directly and avoid the entire question of initializing and cleaning
up a recordset variable.
As to your question, it's always important to disambiguate variable
types. Given that ADO has a Recordset object just like DAO, but
which is completely incompatible, it's wise to disambiguate in all
cases.
If you did only:
Dim rs As Recordset
and ADO was first in the references list, then you'd get an error
when you tried to assign the RecordsetClone to it, as the
RecordsetClone is always a DAO recordset. You'd get a type mismatch.
But, as I said, there's no reason you should ever even need to do
this with a RecordsetClone.
In all other cases, disambiguating produces better, more
maintainable code.