Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

End of Record?

Hi guys, I'm kind of new. :WAVE: Been doing some searching, but haven't quite found a way to do this yet. Using VB6, btw.

What I'm doing is accessing an Access db, returning a recordset, and cycling through the recordset inserting the data into an excel file
(any suggestions are appreciated, too, btw)

what I'm having trouble with is my loop. is there a way to determin when reading the fields that it is at the end of a record, and proceed to the next one? I have part of my loop commented out, but...

i have...this:

q = "SELECT * FROM " & tableName
Call DoQuery(cn, q, cmd, rsResults)

count = 0
xlCol = 0
If rsResults.EOF = False Then
rsResults.MoveFirst

Do
' Do
' moWB.Sheets("Sheet1").Cells(count + 1, xlCol + 1).Value = rsResults.Fields(xlCol)
' xlCol = xlCol + 1
' Loop Until rsResults.c

rsResults.MoveNext
count = count + 1
Loop Until rsResults.EOF = True
End If

Call closeConnection(cn, cmd, rsResults)


thanks in advance!
[1259 byte] By [chupacabra] at [2007-11-11 8:50:23]
# 1 Re: End of Record?
The Fields collection has a Count property which will tell you how many columns there are in a row.
pclement at 2007-11-11 17:24:53 >
# 2 Re: End of Record?
The Fields collection has a Count property which will tell you how many columns there are in a row.

...awesome!

I really cant believe I didnt know that...or find that, even. I thought there would be something like that though.

Thanks a lot! :D
chupacabra at 2007-11-11 17:26:03 >
# 3 Re: End of Record?
There is also another way to do what I was trying to do.

Create a variable as ADODB.Field and do a

Dim fldField as ADODB.Field

For Each fldField In rsResults.Fields

...

Next fldField



rather than...

Do
moWB.Sheets("Sheet1").Cells(rowcount, xlCol + 1).Value = rsResults.Fields(xlCol)
xlCol = xlCol + 1
Loop Until xlCol = rsResults.Fields.count

any ideas on which is more efficient, if there IS any difference. both ways work
chupacabra at 2007-11-11 17:27:02 >