Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

get each row from recordset into excel worksheet

I have been using the vba command
wks.Range("A2").CopyFromRecordset qdf.OpenRecordset

to return the recordset but it appears to be missing some rows.

I have checked the parameters passed to the query and they are correct.

is there a way to get each row from the recordset one by one?

ie movefirst then get row then movenext and so on until the end of the recordset?

this way i can test better. I am in excel vba.

  For Each prm In qdf.Parameters
  Debug.Print prm.Name, prm.Value
Set wks = Sheets("CWCodesToMatch")
Dim iCols As Long

For iCols = 0 To qdf.OpenRecordset.Fields.Count - 1
    wks.Cells(1, iCols + 1).Value = qdf.OpenRecordset.Fields(iCols).Name
wks.Range(wks.Cells(1, 1), _
    wks.Cells(1, qdf.OpenRecordset.Fields.Count)).Font.Bold = True
wks.Range("A2").CopyFromRecordset qdf.OpenRecordset

Open in new window

1 Solution
You should be able to loop through the recordset using

Do While Not qdf.OpenRecordset.EOF
' Loop through the fields again and copy the info in each cell


Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now