How to code data driven form control in VBA ?

  • Thread starter Thread starter Jean
  • Start date Start date
J

Jean

Hi,

I am using MS ACCESS 2000. Is it possible to execute
dynamic VBA code ?

I have 10 toggle buttons.

tog1
tog2
tog3
tog4
tog5
..
..
..
tog10

I need to set each toggle button either on or off based on
the data stored in a data array.

The array is created from a VBA Split command. So the
array length is vary.

For Example, the following 4 array elements shows the
toggle button that need to be set on.

x{0) = 2
x{1} = 4
x{2} = 7
x(3) = 10

How do I code in VBA to resemble something like this ?

Dim x As Variant
Dim i As Long
x = Split(Me.Answer_SysUse, ",")
For i = 0 To UBound(x)
"Tog & X(i)" & .Value = True ???????
Next i

Thanks

Jean
 
Jean said:
Hi,

I am using MS ACCESS 2000. Is it possible to execute
dynamic VBA code ?

I have 10 toggle buttons.

tog1
tog2
tog3
tog4
tog5
.
.
.
tog10

I need to set each toggle button either on or off based on
the data stored in a data array.

The array is created from a VBA Split command. So the
array length is vary.

For Example, the following 4 array elements shows the
toggle button that need to be set on.

x{0) = 2
x{1} = 4
x{2} = 7
x(3) = 10

How do I code in VBA to resemble something like this ?

Dim x As Variant
Dim i As Long
x = Split(Me.Answer_SysUse, ",")
For i = 0 To UBound(x)
"Tog & X(i)" & .Value = True ???????
Next i

Thanks

You're actually very close. Try this:

For i = 0 To UBound(x)
Me.Controls("Tog" & X(i)).Value = True
Next i
 
Back
Top