Access: Runtime Error 13 Type Mismatch

I am getting runtime error 13 at the end of the following code:

Sub plausibilitaet_check()

Dim rs As DAO.Recordset
Dim rs2 As ADODB.Recordset
Dim db As database
Dim strsql As String
Dim strsql2 As String
Dim tdf As TableDef




Set db = opendatabase("C:\Codebook.mdb")
Set rs = db.OpenRecordset("plausen1")

Set rs2 = CreateObject("ADODB.Recordset")
rs2.ActiveConnection = CurrentProject.Connection


For Each tdf In CurrentDb.TableDefs

   If Left(tdf.Name, 4) <> "MSys" Then
        rs.MoveFirst
        strsql = "SELECT * From [" & tdf.Name & "] WHERE "



        Do While Not rs.EOF
            On Error Resume Next

            strsql2 = "select * from table where GHds <> 0"
            Set rs2 = CurrentDb.OpenRecordset(strsql2)

      

The error occurs when setting rs2 = CurrentDb.OpenRecordset (strsql2)

Can anyone see where I am going wrong?

+1


source to share


2 answers


You are mixing ADO and DAO. In this case rs2 must be a DAO Recordset.



Sub plausibilitaet_check()

Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim db As database
Dim strsql As String
Dim strsql2 As String
Dim tdf As TableDef

Set db = opendatabase("C:\Codebook.mdb")
Set rs = db.OpenRecordset("plausen1")


For Each tdf In CurrentDb.TableDefs

   If Left(tdf.Name, 4) <> "MSys" Then
        rs.MoveFirst
        strsql = "SELECT * From [" & tdf.Name & "] WHERE "

        Do While Not rs.EOF
            On Error Resume Next

            strsql2 = "select * from table where GHds <> 0"
            Set rs2 = CurrentDb.OpenRecordset(strsql2)

      

+2


source


CurrentDB.OpenRecordset returns a DAO.Recordset instance. You are trying to assign the result to ADODB.Recordset

Change the definition of rs2 to



dim rs2 as DAO.Recordset

+3


source







All Articles