Solved

I need to iterate through a RecordSet in VBA and display that data

Posted on 2011-09-08
2
313 Views
Last Modified: 2012-05-12
The following line is executing with no errors, which make me pretty sure Myrecordset has valid data in it, that I can extract and display:

Myrecordset.Open MyCommand, , adOpenDynamic, adLockReadOnly


I would like to find out how to:

1) Extract the data
2) Display that data in Excel 2007

Thanks.
0
Comment
Question by:newbieweb
2 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 36503838
Like I said in the other question, use CopyFromRecordset.
Worksheets("Sheet1").Range("A1").CopyFromRecordset Myrecordset

Open in new window

This will put the data in Sheet1 starting at A1, it won't have headers though.

If you want headers, this will add the fields names in row 1 and the data in row 2 down.
Set rng = Worksheets("Sheet1").Range("A1")
For Each fld In Myrecordset.Fields

        rng.Value = fld.Name
        Set rng = rng.Offset(,1)
Next fld

Worksheets("Sheet1").Range("A2").CopyFromRecordset Myrecordset

Open in new window

0
 

Author Closing Comment

by:newbieweb
ID: 36504081
Thanks a million!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now