LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default CopyFromRecordset does nothing

Hello all.

I am using Excel 2002 and Windows 2000.

I've been working on a Excel VBA program that uses ADO to get data
from an Access database. Several connections and queries are made
throughout the program, and I've always just used ADO's .GetRows
method to assign the data in the recordset to a two-dimensional
variant array. After that, of course, the data has to be TRANSPOSEd,
and all is fine.

I thought this was "just how it's done".

Then I stumbled across the Range object's .CopyFromRecordset method.
Lo and behold, it seemed that I would be able to put my recordset data
directly into a spreadsheet! No more putting it into a
two-dimensional variant array and TRANSPOSE-ing it!

Alas, after making the adjustments to my code, it does not seem to
work.

I get no errors at all-- it's just that after the line of code with
the .CopyFromRecorset method, my spreadsheet is still blank.

Makes me realize why errors are nice. At least then you have a
starting point for troubleshooting.

Here is the relevant code:

------------------------------------------------------------
Dim adoConnection As ADODB.Connection
Dim adoRecordset As ADODB.Recordset
Dim strConnection As String
Dim strSQL As String

Set adoConnection = New ADODB.Connection
Set adoRecordset = New ADODB.Recordset

' strFilepath is defined in a module
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
strFilepath
adoConnection.Open strConnection

' build the query string
strSQL = "SELECT * FROM ExcelAnalyteGraph WHERE Location = '" &
lstWell.Text _
& "' AND Name = '" & lstAnalyte.Text

' get the results of the query
adoRecordset.LockType = adLockOptimistic
adoRecordset.CursorLocation = adUseClient
adoRecordset.Open strSQL, adoConnection

With shtData
.Select
.Cells(2, 1).CopyFromRecordset adoRecordset ' after this, shtData
is still blank!
End With

adoRecordset.Close
adoConnection.Close
Set adoRecordset = Nothing
Set adoConnection = Nothing
------------------------------------------------------------


Can anyone please tell me what I am missing?

I do not want to go back to the .GetRows/two-dimensional variant
array/TRANPOSE approach I was previously using!

Thanks in advance,

--emil
 
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
CopyFromRecordset Problem sunzj Excel Discussion (Misc queries) 0 August 2nd 07 06:32 PM
Format data in Excel after using copyfromrecordset jj Excel Discussion (Misc queries) 2 June 13th 07 06:48 AM
copyfromrecordset performance eli silverman Excel Programming 2 January 6th 04 09:29 PM
CopyFromRecordset - Is there a way to filter data that's copied? Mark[_22_] Excel Programming 1 November 6th 03 05:10 AM
Copyfromrecordset Bug ? news.btx.dtag.de Excel Programming 1 August 1st 03 07:44 PM


All times are GMT +1. The time now is 04:21 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"