Solved Building and Updating an Array of Variables from a Recordset (1 Viewer)

pooldead

Registered User.
Local time
Today, 03:01
Joined
Sep 4, 2019
Messages
136
New problem! I'm trying to build an array that stores a variable each time a loop is done in a recordset. The variable is a file path that is built based on a piece of data from the recordset. How would I make sure the code adds each new variable as the code loops, instead of creating a new array each time? My thought so far is but I know it isn't quite there yet:
Code:
'Below is just an example path
Do While Not rs.EOF
    .AddNew
        ePath = "C:\Users\users\" & rs1.fields("Mgr ID") & ".xlsx"
    .Update
    rs.Movenext
Loop
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:01
Joined
Oct 29, 2018
Messages
21,357
Hi. The code you posted adds a new record to a table, not to an array. If you were trying to populate an array in a loop, you would normally have something similar to this:
Code:
ArrayName(index)="something you want to store in the array"
Hope that helps...
 

pooldead

Registered User.
Local time
Today, 03:01
Joined
Sep 4, 2019
Messages
136
Hi. The code you posted adds a new record to a table, not to an array. If you were trying to populate an array in a loop, you would normally have something similar to this:
Code:
ArrayName(index)="something you want to store in the array"
Hope that helps...
So if I'm adding the "ePath" variable to the array, obviously it will change each time with the Mgr ID. Would I do ArrayName(i)=ePath to store the variable in the next position in the array?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:01
Joined
Oct 29, 2018
Messages
21,357
So if I'm adding the "ePath" variable to the array, obviously it will change each time with the Mgr ID. Would I do ArrayName(i)=ePath to store the variable in the next position in the array?
Yes, that would be the idea. As long as you increment (i) with each pass through the loop.
 

Users who are viewing this thread

Top Bottom