tags:

views:

1677

answers:

2

Hi,

I am gettin 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 eror occurs at Set rs2 = CurrentDb.OpenRecordset(strsql2)

Can someone see where I am goin wrong

A: 

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

Change the rs2 definition to

dim rs2 as DAO.Recordset

shahkalpesh
+1  A: 

You are mixing up ADO and DAO. In this case rs2 should 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)
Remou
tksy
You need to tidy up your code and set up suitable recordset types for each recordset. The sample code I provided in that thread relates to using an ADO schema to get tables that contain a particular field in order to avoid the error you were getting. An ADO recordset may not be necessary.
Remou
tksy
or Is it possible to query a recordset
tksy
Not in the way I think you mean, but it is hard to say without an example of what you want to do.
Remou
like i have select * from table where d = 0 in a recordsetcan i run some more queries on the data in this recordset
tksy
You can search within the recordset, but if you want to sort or filter, you will have to build another recordset based on the first. It is probably easiest to simply create a new SQL string.
Remou