Can't open recordset

  • Thread starter Thread starter Robert Chapman
  • Start date Start date
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...
 
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.
 
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.
 
-----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.
 
Back
Top