Cycle through controls to assign Source

  • Thread starter Thread starter Steven Britton via AccessMonster.com
  • Start date Start date
S

Steven Britton via AccessMonster.com

How can I take my array and assign it two controls on a form dynamically?
To assign a starting value in the array and move through it to assign the
values. This is what I do now, but I know I can do I For Next... But an
not sure how.

Me.Form1.Form.Text0.ControlSource = varPlantName(0)
Me.Form1.Form.Text1.ControlSource = varPlantName(1)
Me.Form1.Form.Text2.ControlSource = varPlantName(2)
Me.Form1.Form.Text3.ControlSource = varPlantName(3)
Me.Form1.Form.Text4.ControlSource = varPlantName(4)
Me.Form1.Form.Text5.ControlSource = varPlantName(5)
Me.Form1.Form.Text6.ControlSource = varPlantName(6)
Me.Form1.Form.Text7.ControlSource = varPlantName(7)
Me.Form1.Form.Text8.ControlSource = varPlantName(8)
Me.Form1.Form.Text9.ControlSource = varPlantName(9)

-Steve
 
It looks like your controls are on a subform. I would use unbound controls
with code like:

Dim intN as Integer
For intN = 0 to 9
Me.Form1.Form("Text" & intN) = varPlantName(intN)
Next
 
Use the controls collection for the form in something like

for i = 0 to Forms!formName.controls.count - 1
Forms!formName.controls(i).controlSource = varPlantName(i)
next i

Of course you could always reference the controls collection using the
Me! in place of the Forms!formName

David H
 
Back
Top