?
Solved

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

Posted on 2011-09-08
2
Medium Priority
?
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Norie earned 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 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