If you declare just a Recordset
without specifying if it's DAO or ADO, Access will decide on its own whether it will be DAO or ADO, depending on the order of your references:
Open a code window, go to Tools --> References, and look at the list there.
It will look something like that:
You see that in this example, there is a reference on DAO ("Microsoft DAO 3.6 Object Library") and ADO ("Microsoft ActiveX Data Objects 2.5 Library").
If you declare your Recordset without specifying the type, Access picks the first of these references (=the one that's more on top of the list) and creates a Recordset of this type.
So in this example, it will be a DAO.Recordset
.
Now back to your question:
You declare your Recordset without specifying the type.
So if the first reference in your Access database is ADO, Access will create an ADODB.Recordset
.
Then you open it with a DAO method, which expects a DAO.Recordset
, and that's why you get the error.
There are two ways to solve your problem:
- Make sure that your Access database only has a reference to ADO or DAO (but not both), then you don't need to specify the type of the recordset.
- If you really need both references, always declare your recordsets as
DAO.Recordset
or ADODB.Recordset
to make sure that it's really of the type that your code expects.