Hi all,
I have a sub-form that has 196 controls on it. The name for each control is a nubmer from 1 to 196.
I'd like to generate a loop that assigns a value to each control.
Is there a way to reference a control through a variable?
This is what I have now, without trying to attempt to reference through string:
(arrLayoutArray is a 28 row by 7 columns array that was generated in a seperate module)
I could do this 196 times, but I will be using this for a lot of variations and that isn't very practical. I tried doing this below:
But I get an error because it's looking for counter2 for the name of the control, where I want it to look at the value. I also tried declaring counter2 as a string and variant and that didn't work either.
Please help!
I have a sub-form that has 196 controls on it. The name for each control is a nubmer from 1 to 196.
I'd like to generate a loop that assigns a value to each control.
Is there a way to reference a control through a variable?
This is what I have now, without trying to attempt to reference through string:
(arrLayoutArray is a 28 row by 7 columns array that was generated in a seperate module)
Code:
Me!sfmSubform.Form![1].Value = arrLayoutArray(1, 1)
Me!sfmSubform.Form![2].Value = arrLayoutArray(1, 7)
Me!sfmSubform.Form![3].Value = arrLayoutArray(1, 2)
Me!sfmSubform.Form![4].Value = arrLayoutArray(1, 3)
Me!sfmSubform.Form![5].Value = arrLayoutArray(1, 4)
Me!sfmSubform.Form![6].Value = arrLayoutArray(1, 5)
Me!sfmSubform.Form![7].Value = arrLayoutArray(1, 6)
Code:
Dim counter As Variant
Dim counter2 As Integer
counter2 = 0
For counter = 1 To 28
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 1)
counter2 = counter2 + 1
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 7)
counter2 = counter2 + 1
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 2)
counter2 = counter2 + 1
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 3)
counter2 = counter2 + 1
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 4)
counter2 = counter2 + 1
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 5)
counter2 = counter2 + 1
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 6)
counter2 = counter2 + 1
Next
Please help!
Comment