Can't open recordset

R

Robert Chapman

Can't understand why the following is producing a type
mismatch error (error 13). Never had any problem with
this, should be very simple. All I have in my database is
the module of code and the table
called "SuppressionData". It finds the table (otherwise
there would be a table not identified error) so what is
the problem here?? I've tried all the variations
(dbOpenTable, etc) but they shouldn't make any difference
anyway. Code below - the "Set rs = ..." line is what
geenrates the error.

TIA,

Rob

Sub AddSuppressionData()
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("SuppressionData")

etc...
 
S

Sandra Daigle

Hi Robert,

If you have references to both the DAO and ADO libraries then you need to
disambiguate the reference to a recordset since both libraries have
Recordset objects. In your case, you probably have the ADO library listed
before the DAO library so an ambiguous declaration of Recordset will result
in an ADO recordset rather than a DAO one. Since db.OpenRecordset results in
a DAO recordset you get the Type mismatch error.

So, how to fix this:

Dim db As DAO.Database
Dim rs As DAO.Recordset

Also, if you are not using ADO you should remove it from your references.
The fewer libraries listed the faster references can be resolved. Regardless
it is best to disambiguate object references when possible.
 
M

Mark Reed

Rob,

You need to tell Access whether you are using DAO (Data Access Objects) or
ADO (ActiveX Data Objects) library.

I use DAO for my database on a standalone PC, for my database I would
re-write your code as follows

Sub AddSuppressionData()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("SuppressionData")

At the moment Access doesn't know which library you intend to use.

For more info see..

http://support.microsoft.com/default.aspx?scid=kb;en-us;181542&Product=acc20
00

HTH

Mark mcse.
 
R

Robert Chapman

-----Original Message-----
Rob,

You need to tell Access whether you are using DAO (Data Access Objects) or
ADO (ActiveX Data Objects) library.

I use DAO for my database on a standalone PC, for my database I would
re-write your code as follows

Thanks to both of you, I'll just take out the ADO
Reference and it'll be back to normal. Thanks.
 

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