Type mismatch

A

Alex

I'm using Access 2002. The following code gives me a type mismatch:

Private Sub Command13_Click()

Dim Rs As Recordset

Set Rs = Me.Recordset

End Sub

If I change my Dim statement to:

Dim Rs As ADODB.Recordset

I still get a type mismatch.

If I try the following:

Dim Rs As DAO.Recordset

then I get the error: Compile error. User-defined type not defined.

I have a reference to Microsoft ActiveX Data Objects 2.5 Library. The
Microsoft DAO Object Libraries are not referenced (they are not checked in the
References dialog). Can somebody please explain to me what's going on?
Ultimately what I'm trying to do is get access to the form's recordset. I'm
working on a company wide application and I already checked that the
workstations are using ADO, not DAO in the Access database applications that
they currently have. I want them to keep using what they are using and not
have to require them to make any changes.
 
B

Brendan Reynolds

Did you read the article at the URL I posted, Alex?

If you didn't like my answer and would prefer to look for another one,
that's fine, but it would have been better to continue in the same thread.
By starting a new thread like this, people who have not seen the previous
thread are likely to waste their time telling you the same things that I did
in the other thread.

As the article explains, in an MDB the Recordset and RecordsetClone both
return a DAO recordset unless you have previously assigned an ADO recordset
to the Recordset property of the form. In Access 2000 (the version current
at the time the article was written) this always resulted in a read-only
form. In Access 2003 it does not (though you have to be careful to set the
necessary properties of the recordset). I don't have Access 2002 available
to test, but if I remember correctly I believe that the last time this
subject came up someone said that the behaviour in Access 2002 was the same
as in Access 2003.

In short, if you want to get an ADO recordset back from the form's Recordset
or RecordsetClone properties in an MDB, you need to assign an ADO recordset
to the form's Recordset property first. If you prefer to deal with the
default DAO recordset, then you must add a reference to the DAO object
library. And, as I explained before, it is highly unlikely that doing so
will require any changes on the target PCs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top