Is it possibile to access a recordset using a variable for the name ?
For example, i've a table with 10 fields called Name01,Name02,Name03.....Name10. I need to cycle through them so it would be nice to just use one instruction insted of repeating the same one with 10 different name.
This is the code i'm using now
Sal01 = rsUtility!Order01
Sal02 = rsUtility!Order02
....
Sal10 = rsUtility!Order10
This is what i would like to accomplish :
for i = 1 to 10
VariableName = "Order" & i
Sal(i) = rsUtility!VariableName
next i
Here you go:
for i = 1 to 10
VariableName = "Order" & i
Sal(i) = rsUtility(VariableName)
next i
Since your variables have a 2 digit ending, you gotta use a proper format and not just "Order" & i
, because it will result in Order1
and not Order01
For i = 1 to 10
Sal(i) = rsUtility("Order" & Format(i,"00") )
Next i
The loop above will assign a value to a corresponding array element from DB variables in the range from Order01
to Order10
inclusive
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.