Jeff said:
Nah, you cannot copy a RecordSet!
You could tweak my dumpRs routine to write to a table instead of the
debug window.
Sub dumpRs(rs As Recordset)
If rs.RecordCount = 0 Then Exit Sub 'don't bother
rs.MoveFirst
dumpRecord rs, True
Do Until rs.EOF
dumpRecord rs
rs.MoveNext
Loop
End Sub
Sub dumpRecord(rs As Recordset, Optional fieldnames = False)
Dim fd As Field
For Each fd In rs.Fields
If fd.OrdinalPosition > 0 Then Debug.Print ", ";
If fieldnames Then
Debug.Print fd.Name;
Else
Debug.Print fd.Value;
End If
Next
Debug.Print
End Sub
Or, if you want something more cut to the job:
Sub dumpToTable(rs As Recordset, cTable As String)
Dim fd As Field
Dim fdE As Field 'to enum the recordset
Dim td As TableDef
Dim db As Database
Dim rsT As Recordset 'target recordset on new table
If rs.RecordCount = 0 Then Exit Sub 'don't bother
'copy the table structure
Set db = CurrentDb
Set td = db.CreateTableDef(cTable)
For Each fdE In rs.Fields
Set fd = td.CreateField(fdE.Name, fdE.type, fdE.Size)
td.Fields.Append fd
Next
db.TableDefs.Append td
Set td = Nothing
'dump the recordset
Set rsT = db.OpenRecordset(cTable)
rs.MoveFirst
Do Until rs.EOF
rsT.AddNew
For Each fdE In rs.Fields
rsT(fdE.Name) = fdE.Value
Next
rsT.Update
rs.MoveNext
Loop
rsT.Close
Set rsT = Nothing
Set db = Nothing
End Sub