Type Mismatch

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I have avoided creating record sets, mostly because i can
never get them to work, instead i used temp tables.

I have decided to learn to use record sets if it kills
me. Well, it is.

When I run the following code I get a Type Mismatch error
on the Set rstSpecialists line, why? The table contains 2
fields SpEmail txt(50) and SpID integer.

Dim varSpecialistID As Integer
Dim rstSpecialists As Recordset
Dim strSQL As String

strSQL = "SELECT * FROM tbl_SealReh_Details"
Set rstSpecialists = CurrentDb.OpenRecordset(strSQL)
rstSpecialists.MoveLast
Debug.Print rstSpecialists.RecordCount
rstSpecialists.Close

Thanks for your help,

Jim
 
Hi Jim,

Have you used Tools>References in the VBA editor to set a
reference to 'Microsoft DAO 3.6 Object Library'? If so,
then try modifying your code to explicitly reference a DAO
recordset:

Dim rstSpecialists As DAO.Recordset

If you haven't then I suggest that you do and then use the
syntax above.

By default a new Access database does not set this
reference but uses ADO instead and as both libraries have
a RecordSet object things can get a little confusing.

hth

chas
 
For the code that you put in your original post, you need to use the DAO
library. DAO and ADO are two different ways of handling data via recordsets.
DAO is the older method that is still preferred by most ACCESS developers
for work within ACCESS databases (it's designed to work with the Jet engine
that handles the data), and ADO is designed for interacting with other
databases and for ODBC connections.

They're similar but different. If you're working with ACCESS only at this
time, I'd stay with DAO.
 
Back
Top