Vinod Chelladurai
Vinod Chelladurai

Reputation: 539

MS Access Error with DAO Recordset

Am trying to create an empty DAO recordset rs2 whose structure is similar to an existing recordset rs1 (which has more than 200 fields). But I am facing an error which does not happen when I use ADO recordset:

dim rs2 as recordset

With rs2.Fields
    For Each fld In rs.Fields
        .Append fld, adVariant
    Next
End With

Error is wrong number of arguments.

Upvotes: 1

Views: 488

Answers (2)

HansUp
HansUp

Reputation: 97131

ADO allows you to add a field to the Recordset.Fields collection under certain circumstances. That is why the ADO version of your code runs without error.

However, the DAO Fields.Append method can not be used with a Recordset. Instead you would have to add a field to the table, or field expression to the query, which is used as the recordset's data source.

Upvotes: 1

kiks73
kiks73

Reputation: 3778

I know that this solution is not good for performance, but you can give it a try anyway. First, clone the recordset:

Set rs2 = rs.clone

And then, if you only need the structure, empty it:

Do until rs2.EOF
    rs2.Delete
Loop

Upvotes: 0

Related Questions