ACCESSDUMMY
Programmer
I'm trying to use a variable in a loop for shortening my VBA code. I have 100 fields in a table that I need to run the same code on, but I don't know how to use a variable to reference a field name. Is this possible?
The fields in the table are as follows:
Fund 1
Fund 2
Fund 3
Fund 4
etc...
all the way to Fund 100
Here's the code I have so far.
Do Until rst.EOF
For i = 1 To 100
fieldvar = "rst.[Fund " & i & "]"
If fieldvar > 0 Then
rst2.AddNew
rst2!Employee = rst!Employee
fundvar = "Number = '" & i & "'"
rst3.FindFirst fundvar
If rst3.NoMatch Then
rst2![Fund Letter] = " "
Else
rst2![Fund Letter] = rst3![Corresponding Fund Letter]
End If
rst2![Fund %] = rst!["Fund " & i]
rst2.Update
End If
Next
Loop
rst.Close
rst2.Close
rst3.Close
Any help would be greatly appreciated!
The fields in the table are as follows:
Fund 1
Fund 2
Fund 3
Fund 4
etc...
all the way to Fund 100
Here's the code I have so far.
Do Until rst.EOF
For i = 1 To 100
fieldvar = "rst.[Fund " & i & "]"
If fieldvar > 0 Then
rst2.AddNew
rst2!Employee = rst!Employee
fundvar = "Number = '" & i & "'"
rst3.FindFirst fundvar
If rst3.NoMatch Then
rst2![Fund Letter] = " "
Else
rst2![Fund Letter] = rst3![Corresponding Fund Letter]
End If
rst2![Fund %] = rst!["Fund " & i]
rst2.Update
End If
Next
Loop
rst.Close
rst2.Close
rst3.Close
Any help would be greatly appreciated!