View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default CopyFromRecordset not starting at current row

Adi,

this generic routine works for me to dump a recordset to a new workbook
starting at an optional start position, including the field headers, using
ADO 2.7 on Office XP, Win XP.

Sub DumpRecordset(rsName As adodb.Recordset, Optional lStartPos As Long)
Dim W As Workbook
Dim nField As Integer
Set W = ActiveWorkbook
Workbooks.Add
With rsName
For nField = 1 To .Fields.Count
Cells(1, nField).Value = .Fields(nField - 1).Name
Next nField
.MoveFirst
If Not IsEmpty(lStartPos) Then .Move lStartPos
End With
Cells(2, 1).CopyFromRecordset rsName
End Sub

Robin Hammond
www.enhanceddatasystems.com

"adi" wrote in message
...
I can't get the CopyFromRecordset method to start at a specific row.
Details:
Using Access and Excel 2000, rst is an adodb.recordset in an mdb, range is

an excel.range object.
"range.CopyFromRecordset rst" works as expected.
"range.CopyFromRecordset rst, 10" copies the first 10 records as expected.
But after moving to some record, e.g. using "rst.move 5",

"range.CopyFromRecordset rst, 10" will still copy the first 10 records of
the rst, instead of starting with the 5th record as I want it to.
According to

http://msdn.microsoft.com/library/de...mRecordset.asp
copying should begin at the current row of the recordset. (In fact, the
first row becomes the current row when I call the CopyFromRecordset method,
don't know why...)
Please help! Thanks.