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

x
  • 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
Next
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
Next
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

0
PeterBaileyUk
Asked:
PeterBaileyUk
1 Solution
 
LIONKINGCommented:
You should be able to loop through the recordset using

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

qdf.OpenRecordset.MoveNext
Loop
0

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