Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Using an ADODB.Recordset in Excel 2007

I have seen a few code examples that use ADO to open a
"connection" to an Excel 2007 file. After a connection is established,
I typically see code such as this:

'=======================================
' Check to make sure we received data.
If Not rsData.EOF Then
Sheet1.Range("A1").CopyFromRecordset rsData
Else
MsgBox "No records returned.", vbCritical
End If
'======================================

The above code pastes data from the "rsData" recordset object
into Sheet1 starting at range A1. My question is, what if I don't
want to paste my recordset onto the spreedsheet?? Can't I
simply assign specific data values from the recordset to a Visuabl Basic
variable??

Thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Using an ADODB.Recordset in Excel 2007

Robert Crandal wrote on 9/25/2010 :
I have seen a few code examples that use ADO to open a
"connection" to an Excel 2007 file. After a connection is established,
I typically see code such as this:

'=======================================
' Check to make sure we received data.
If Not rsData.EOF Then
Sheet1.Range("A1").CopyFromRecordset rsData
Else
MsgBox "No records returned.", vbCritical
End If
'======================================

The above code pastes data from the "rsData" recordset object
into Sheet1 starting at range A1. My question is, what if I don't
want to paste my recordset onto the spreedsheet?? Can't I
simply assign specific data values from the recordset to a Visuabl Basic
variable??

Thank you!


Yes! You don't have to write data to a spreadsheet because you can
manipulate the recordset however you want. You could, for example, dump
it into an array or parse individual records into variables.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Using an ADODB.Recordset in Excel 2007

Exactly HOW do I dump the data into an array or a variable?
I see that the Recordset has various properties and members, but
I'm not sure how to dump anything into an array.

Thank you!


"GS" wrote in message
...

Yes! You don't have to write data to a spreadsheet because you can
manipulate the recordset however you want. You could, for example, dump it
into an array or parse individual records into variables.

--


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Using an ADODB.Recordset in Excel 2007

Robert Crandal brought next idea :
Exactly HOW do I dump the data into an array or a variable?
I see that the Recordset has various properties and members, but
I'm not sure how to dump anything into an array.

Thank you!


"GS" wrote in message
...

Yes! You don't have to write data to a spreadsheet because you can
manipulate the recordset however you want. You could, for example, dump it
into an array or parse individual records into variables.

--


Basically, you'd have to walk through the recordset a load each record
into an array. The problem is that each record will contain many
different values. It might be easier to dump the recordset onto a blank
worksheet first, then dump the worksheet into a dynamic array. This, if
I'm not mistaken, should result in an array of arrays wherein each
element of the array contains an array of each record's values.

You'll have to manage the order since (as I see by your connection
string) you don't have headers.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Using an ADODB.Recordset in Excel 2007

If you want to create an array from the recordset use GetRows.

arrValues = rsData.GetRows



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Using an ADODB.Recordset in Excel 2007

norie laid this down on his screen :
If you want to create an array from the recordset use GetRows.

arrValues = rsData.GetRows


Thanks! I completely forgot about that...

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing ADODB recordset to excel sheet bhavesh78 Excel Programming 2 December 9th 05 04:51 PM
VBA excel - problem with having clause in sql with adodb.connection/recordset ukp9999 Excel Programming 3 November 21st 05 07:48 AM
0 with ADODB Recordset Stefen Percoco Excel Programming 1 July 8th 04 09:54 PM
adodb.recordset with excel nate axtell Excel Programming 14 June 11th 04 01:32 PM
ADODB Recordset Seth[_3_] Excel Programming 0 August 5th 03 02:15 PM


All times are GMT +1. The time now is 01:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"