How to Dynamically Reference Objects on a Form?

G

Guest

I am creating a form with a grid of objects (text boxes and buttons). The
grid's dimensions sometimes change: sometimes its' 4x4, sometimes 6x7,
sometimes 10x10, etc. based on parameters set before opening the form. When
the form opens, the objects are created and placed evenly on the form, with
names that reflect their postion in the grid. (For example the button in row
2, column 2 is named "Button_02_02".

What I can't do is, based on the user's interaction with any object, set
properties of related objects immediately surrounding that object. (For
example, user clicks on Button_02_02, then On click, dynamically read/set
properties of objects left, right, above, and below. So in this case, in
code, use the row & column components of the object name "Button_02_02" and
reference the surrounding buttons: Button_02_01, Button_02_03, Button_01_02,
Button_03_02.)

Any advice on ways to do this is much appreciated. Thanks.
 
D

Douglas J. Steele

To refer to Button_02_01, you'd use something like:

DIm strVariable As String

strVariable = "Button_02_01"
Me.Controls(strVariable).BackColor = ....
 
G

Guest

thanks! it worked like a charm.

Douglas J. Steele said:
To refer to Button_02_01, you'd use something like:

DIm strVariable As String

strVariable = "Button_02_01"
Me.Controls(strVariable).BackColor = ....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top