fill multiple unbound textboxes using recordset

  • Thread starter Thread starter potato_basher
  • Start date Start date
P

potato_basher

Hi,

I have a report that has 30 unbound text boxes in the detail section
The recordset has 30n entries. I have this code to fill them:


box1 = rs!total
rs.movenext
box2 = rs!total
rs.movenext
box3 = rs!total
rs.movenext
box4 = rs!total
rs.movenext
...

Is there a way to refer to the unbound boxes with a variable so I ca
loop through them? I guess it is something to do with controls, but
get lost trying to find the right one for the value in the textbox.

Cheers
J
 
A little messier than we would like, but try

' BEGIN CODE

Dim num as integer
Dim controlName as String
Dim co as Control

for num = 1 to 30
controlName = "box" & num

for each co in Form.Controls
if co.Name = controlName then
co.Value = rs!total
rs.MoveNext
exit for
end if
next
next num

' END CODE

I didn't spend a ton of time on this to see if there might be a more
performance friendly way, but this should work, and for 30 controls it
shouldn't perform too badly.
 
Back
Top