Vb for Access code not work

I am using the following code (which is the same as i used in another database) but it stops at set rstCLP    saying run time error 13 type mismatch

   'add DAO 3.6 object library
    Dim rstDB As Database
    Dim rstCLP As Recordset
    Dim rstSumm As Recordset
    Set rstDB = CurrentDb
    Set rstCLP = rstDB.OpenRecordset("SELECT * FROM CLP")
    Set rstSumm = rstDB.OpenRecordset("SELECT * from CLPSummary")

CLP and CLPSummary are valid tables (linked) in the current database.  My plan is to read from the CLP table and write to the CLPSummary table
Who is Participating?
Arthur_WoodConnect With a Mentor Commented:
try this change (I assume that you are using this code in Access 2000+):

   Dim rstDB As New Database
    Dim rstCLP As  New DAO.Recordset
    Dim rstSumm As  New DAO.Recordset

   Set rstDB = CurrentDb
   Set rstCLP = rstDB.OpenRecordset("SELECT * FROM CLP")
   Set rstSumm = rstDB.OpenRecordset("SELECT * from CLPSummary")

ADO is the default Data Access Technology in Access 2000 ( and newer) and thus a Recordset is declared as ADO.Recordset by default.  An ADO recordset is a DIFFERENT TYPE from a DAO Recordset, hence the Type Mismatch.

Could you try the following:

    Dim rstDB As New Database
    Dim rstCLP As  New Recordset
    Dim rstSumm As  New Recordset

   rstDB = CurrentDb
   rstCLP = rstDB.OpenRecordset("SELECT * FROM CLP")
   rstSumm = rstDB.OpenRecordset("SELECT * from CLPSummary")

jimcrintAuthor Commented:
The DAO was the answer but the new in the declarations were not allowed or required in this context.

I am now able to access the tables and manipulate the data to my hearts content

Thank you
that is correct, in fact, the use of New in a Declaration is NOT a good idea, and I should have noticed that.  I simply Cut and Pasted the previous suggestrion, and changed the declaration to DAO. for the recordset object.  Am I baaaaad or what - wasn't looking carefully.

Glad you have resolved the issue.  Glad to be of some small measurwe of assistance.

You can accomplish the same end result, by moving the DAO reference ABOVE the ADO reference, or by deleting the ADO reference altogether (Tools/References).

Arno KosterCommented:
maybe you could use a


clause ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.