Solved

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

Posted on 2011-09-08
2
312 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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