Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to locate the end of a recordset

"CLamar" wrote:

How do you find the end of a recordset, so it can be used in a loop. I tried
the EOF command but it wont enter the loop when i use it. Here is an example
of the code. The second for loop with the * is the one giving me problems

Set Recordset = New ADODB.Recordset
With Recordset
Src = "SELECT * FROM Table1"
.Open Source:=Src, ActiveConnection:=Connection

For Col = 0 To Recordset.Fields.Count - 1
Sheets("DataTable").Range("A1").Offset(0, Col).Value =
Recordset.Fields(Col).Name
Next

Sheets("DataTable").Range("A1").Offset(1, 0).CopyFromRecordset
Recordset

** For Row = 2 To Recordset.EOF
Sheets("Sheet1").LstBatchnum.AddItem
Sheets("DataTable").Cells(Row, 1)
Next Row
End With

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
ADG ADG is offline
external usenet poster
 
Posts: 76
Default How to locate the end of a recordset

Hi

You can use recordset..RecordCount to find the number of rows in the
recordset. But beware, in some versions of office this does not give the
right count until you have moved to the end of the recordset, so preceed it
with recordset.MoveLast

HTH
--
Tony Green


"CLamar" wrote:

"CLamar" wrote:

How do you find the end of a recordset, so it can be used in a loop. I tried
the EOF command but it wont enter the loop when i use it. Here is an example
of the code. The second for loop with the * is the one giving me problems

Set Recordset = New ADODB.Recordset
With Recordset
Src = "SELECT * FROM Table1"
.Open Source:=Src, ActiveConnection:=Connection

For Col = 0 To Recordset.Fields.Count - 1
Sheets("DataTable").Range("A1").Offset(0, Col).Value =
Recordset.Fields(Col).Name
Next

Sheets("DataTable").Range("A1").Offset(1, 0).CopyFromRecordset
Recordset

** For Row = 2 To Recordset.EOF
Sheets("Sheet1").LstBatchnum.AddItem
Sheets("DataTable").Cells(Row, 1)
Next Row
End With

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to locate the end of a recordset

Thanks that sounded like a great idea and it should have worked but it
doesnt. It doesnt give me an error when I use the RecordCount but it doesnt
enter the loop. When I use .MoveLast it gives me the error "Expected
Function or Variable". So can you tell me if i am doing something wrong or
give me another suggestion

Thanks CLamar


"ADG" wrote:

Hi

You can use recordset..RecordCount to find the number of rows in the
recordset. But beware, in some versions of office this does not give the
right count until you have moved to the end of the recordset, so preceed it
with recordset.MoveLast

HTH
--
Tony Green


"CLamar" wrote:

"CLamar" wrote:

How do you find the end of a recordset, so it can be used in a loop. I tried
the EOF command but it wont enter the loop when i use it. Here is an example
of the code. The second for loop with the * is the one giving me problems

Set Recordset = New ADODB.Recordset
With Recordset
Src = "SELECT * FROM Table1"
.Open Source:=Src, ActiveConnection:=Connection

For Col = 0 To Recordset.Fields.Count - 1
Sheets("DataTable").Range("A1").Offset(0, Col).Value =
Recordset.Fields(Col).Name
Next

Sheets("DataTable").Range("A1").Offset(1, 0).CopyFromRecordset
Recordset

** For Row = 2 To Recordset.EOF
Sheets("Sheet1").LstBatchnum.AddItem
Sheets("DataTable").Cells(Row, 1)
Next Row
End With

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default How to locate the end of a recordset

Hi CLamar,

I think since you're reading the spreadsheet instead of the recordset, you
should be referencing a count of the rows of records.<IMO Try changing the
loop start to:

For Row = 2 To Cells(Rows.Count, 1).End(xlUp).Row

HTH
Regards,
Garry
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
Need ADO Recordset Help Mr B[_2_] Excel Programming 9 April 21st 06 04:51 PM
Several sql queries with the same recordset fbonnard Excel Programming 2 November 2nd 04 05:50 PM
DAO Recordset in Excel Andy Excel Programming 2 October 3rd 04 12:13 AM
Type recordset/recordset? FlaviusFlav[_9_] Excel Programming 4 May 24th 04 12:16 PM
Recordset Stephan Kassanke Excel Programming 0 September 10th 03 04:45 PM


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