Hi all.
Backdrop: I have an Access form with numerous labels (Label, Label102, Label103, etc.)
In code, to make them easier to work with, I set up a number of label arrays and grouped the form's labels into them. Names of arrays are lblLeft, lblRight, lblTop, lblBottom, etc.
I need a sub that gets the .BackColor from a specific element of a specific array. The array name is passed as a parameter to the sub. The index is provided in the code as I work through the array. I could do this fairly easily if I wrote one sub for each group, but I want to write a single sub.
............
The problem. I've tried multiple methods to dynamically build the name of the control and get its .BackColor property, but it fails every time.
What I've tried:
Me.Controls("Label206").BackColor 'This works, but it references the control on the form, not the array control
Me.Controls("lblLeft(1)").BackColor 'Does not work, "Access cannot find the Field 'lblLeft(1)'...
CallByName(Label206, "BackColor", VbGet) 'This works but for the form control, not the array control
CallByName(lblLeft(1), "BackColor", VbGet) 'This works, but I referenced the array control itself
I need the following to work:
CallByName("lbl" & ArrayName & "(" & Index & ")", "BackColor", VbGet) 'This does not work, says 'Object required' because it expected the string I passed to be a control.
This worked too:
Dim MyLabel As Label
Set MyLabel = Controls("Label206") form label in quotes
MsgBox (MyLabel.BackColor)
This did not work either:
Dim MyLabel As Label
Set MyLabel = Controls("lblLeft(1)")
MsgBox (MyLabel.BackColor) ' cannot find the Field lblLeft(1)
Dim MyLabel As Label ' THis does not work. Same reason.
Set MyLabel = Controls("lblLeft")
MsgBox (MyLabel(1).BackColor)
I need to be able to dynamically insert the Group name (Left, Right, etc) and the index number, and then access properties of that specific control.
Help?!
Thanks.
Backdrop: I have an Access form with numerous labels (Label, Label102, Label103, etc.)
In code, to make them easier to work with, I set up a number of label arrays and grouped the form's labels into them. Names of arrays are lblLeft, lblRight, lblTop, lblBottom, etc.
I need a sub that gets the .BackColor from a specific element of a specific array. The array name is passed as a parameter to the sub. The index is provided in the code as I work through the array. I could do this fairly easily if I wrote one sub for each group, but I want to write a single sub.
............
The problem. I've tried multiple methods to dynamically build the name of the control and get its .BackColor property, but it fails every time.
What I've tried:
Me.Controls("Label206").BackColor 'This works, but it references the control on the form, not the array control
Me.Controls("lblLeft(1)").BackColor 'Does not work, "Access cannot find the Field 'lblLeft(1)'...
CallByName(Label206, "BackColor", VbGet) 'This works but for the form control, not the array control
CallByName(lblLeft(1), "BackColor", VbGet) 'This works, but I referenced the array control itself
I need the following to work:
CallByName("lbl" & ArrayName & "(" & Index & ")", "BackColor", VbGet) 'This does not work, says 'Object required' because it expected the string I passed to be a control.
This worked too:
Dim MyLabel As Label
Set MyLabel = Controls("Label206") form label in quotes
MsgBox (MyLabel.BackColor)
This did not work either:
Dim MyLabel As Label
Set MyLabel = Controls("lblLeft(1)")
MsgBox (MyLabel.BackColor) ' cannot find the Field lblLeft(1)
Dim MyLabel As Label ' THis does not work. Same reason.
Set MyLabel = Controls("lblLeft")
MsgBox (MyLabel(1).BackColor)
I need to be able to dynamically insert the Group name (Left, Right, etc) and the index number, and then access properties of that specific control.
Help?!
Thanks.