Loops within loops

K

Keith

I seem to be having a Monday morning moment. I have a simple task to code,
but for some reason I can't get my head around it.

I have a recordset open. That's fine. I know that there will only be 8
records in this recordset. What I want to do is populate an Array with a
date that is stored in each record.

I have setup d do while not eof to go through the recordset, I have the
setup a For next loop (1 to 8) to move through the array.

But unless I am mistaken I will have to go right through the array before I
can move to the next record. Am I correct?

Can somebody help me through my Monday morning fog. This should be simple.

How can I move the For Next on by 1 then move the recordset on one?
 
S

Stefan Hoffmann

hi Keith,
I seem to be having a Monday morning moment. I have a simple task to code,
but for some reason I can't get my head around it.
Seems like your forgot your cup of coffee?
I have a recordset open. That's fine. I know that there will only be 8
records in this recordset. What I want to do is populate an Array with a
date that is stored in each record.

Dim Count As Long
Dim Dates() As Date

rs.MoveLast
rs.MoveFirst 'if order is important
Count = rs.RecordCount

ReDim Preserve Dates(Count - 1)

For Count = 0 to Count - 1
Dates(Count) = rs![Date]
rs.MovePrevious
Next Count


mfG
--> stefan <--
 
K

Keith

Hi Stefan,

That will work great.

Thanks for taking the time to help. As I said I was having a Monday Morning
moment.

Keith

Stefan Hoffmann said:
hi Keith,
I seem to be having a Monday morning moment. I have a simple task to code,
but for some reason I can't get my head around it.
Seems like your forgot your cup of coffee?
I have a recordset open. That's fine. I know that there will only be 8
records in this recordset. What I want to do is populate an Array with a
date that is stored in each record.

Dim Count As Long
Dim Dates() As Date

rs.MoveLast
rs.MoveFirst 'if order is important
Count = rs.RecordCount

ReDim Preserve Dates(Count - 1)

For Count = 0 to Count - 1
Dates(Count) = rs![Date]
rs.MovePrevious
Next Count


mfG
--> stefan <--
 
K

Keith Wilby

Keith said:
I seem to be having a Monday morning moment. I have a simple task to code,
but for some reason I can't get my head around it.

I have a recordset open. That's fine. I know that there will only be 8
records in this recordset. What I want to do is populate an Array with a
date that is stored in each record.

I have setup d do while not eof to go through the recordset, I have the
setup a For next loop (1 to 8) to move through the array.

But unless I am mistaken I will have to go right through the array before
I
can move to the next record. Am I correct?

Can somebody help me through my Monday morning fog. This should be
simple.

How can I move the For Next on by 1 then move the recordset on one?

Care to post your code?

Regards,
Keith.
www.keithwilby.com
 
B

Brendan Reynolds

That's odd. I copied and pasted those URLs from the properties of the
relevant pages, but they come up 'not available' for me, too, now.

You should be able to get to the help topics if you go into the VBA editor
and type 'GetRows' in the 'Type a question for help' box.
 
Top