Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba accessing dynamic controls 1

Status
Not open for further replies.

sikyu

Programmer
Jul 14, 2007
3
US
Is there a way to dynamically set a control by its name?

for example, I have a form with a custom calendar.
along the y axis i have dates, and along the x axis i have locations.
The locations can be variable, as i can add locations.

(background: e.g i have a storage facility with X locations, and I want to see in a calendar view which location is rented by which client)

My form creates (or removes) textboxes depending on the amount of locations that are defined.

Each textbox has the name set of X-Y (basically the same as top and left values)

I know I can access the textbox by doing
Code:
me.[500-600] = "valuehere"

However what I would like to be able to do is:
Code:
dim x as integer
dim y as integer
x = 500
y = 600
me.[x & "-" & y] = "valuehere"

However when I try to do this, it looks for the field x & "-" & y, instead of their values.


Currently my workaround for this problem is :
Code:
dim ccont as textbox
for each ccont in me.controls
  if ccont.left = x and ccont.top = y then
    ccont = "valuehere"
    exit for
  end if
next ccont
However with 30 days and 20 locations, that means looping though 600 boxes....

Does anyone know how to either expand the vars, or to set the control without looping?

Any help is greatly appreciated
 
Perhaps this ?
Me.Controls(x & "-" & y) = "valuehere"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks that worked!

I feel silly that it was that easy to fix it :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top