Opening a recordset

R

Ralph Heidecke

Hi:

I've been away from Access programming for a number of years. I have been
trying to open a record set but the code I am using is returning a type 13
"data type mismatch" run time error. The code is in a module attached to the
database. I am using Access 2002 but the file format is Access 2000

the code:

Dim rec As Recordset
Dim db As Database
Dim iRec As Integer

Set db = CurrentDb()
Set rec = db.OpenRecordset("EmpMaster") ' the error occurs here


the database is called stiip.mdb and 'EmpMaster" is a table in stiip.mdb

tia for any assistance.
 
G

George Nicholson

1) In the VB editor: Tools>References. Make sure "Microsoft DAO x.x Object
Librabry" is checked.

2) Change to:
Dim rec As DAO.Recordset
Dim db As DAO.Database

While you've been gone: ADO (ActiveX Data Object Library) was introduced and
was the default (over DAO) in Access 2000 (causing a lot of old code to
"break" like this). Both ADO and DAO have Recordset objects but ADO does not
have a Database object. In the line
Set rst = db.OpenRecordset (yada)
Access 2000 assumes rst is a ADO recordset. db.OpenRecordset(yada) produces
a DAO recordset. Trying to assign one to the other? Type Mismatch.

Making sure you have a reference to the DAO library set (which you probably
already have since "Set db..." didn't raise an "unknown object" error) and
"disambiguating" your variables (i.e., Dim rst as DAO.Recordset, etc.)
should clear things up.

Welcome back!

HTH,
 

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