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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating dynamic control arrays

Status
Not open for further replies.

striker73

MIS
Joined
Jun 7, 2001
Messages
376
Location
US
I want to be able to create a control array of labels. In my experience with VB, you can put a label on your form and set the index value to 1. Then in your code you can Load lblMyLabel(1) and so on.

I am having trouble implementing this with VBA. Do I have to create a label on my form to begin with? How to I create more labels dynamically? Thanks!
 
hmm.. all right then.. on to plan B! thanks!
 
Striker:

You can create a pseudo array by naming all the controls the same except for a numeric identifier (similar to true control arrays). Here is a sample of how I have used it:

For intSvcLoop = 1 To 5
Me("txtTotal" & intSvcLoop).Enabled = False
For intWeekLoop = 1 To 5
Me("txt" & intSvcLoop & intWeekLoop).Enabled = False
Next intWeekLoop
Next intSvcLoop

I have a set of controls named txtTotal1 to txtTotal5. You reference the control with the Me("NameString" & numeric value).

Crude but servicable. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
i have the same problem
=I want to be able to create a control array of labels. In my experience with VB, you can put a label on your form and set the index value to 1. Then in your code you can Load lblMyLabel(1) and so on.

I am having trouble implementing this with VBA. Do I have to create a label on my form to begin with? How to I create more labels dynamically? Thanks!

if u have found the solution pls let me know.
 
what I ended up doing was creating 20 controls (checkboxes in my case) and then only showing the ones I needed. I then hid the others and moved them aside so I could change the window size. It's so annoying because there is a CreateControl() function in VBA that theoretically would actually create a control, however it gives the error that you can't create a control unless you are in design view. The only place I can think of where you can utilize code still in design view is when you are opening a report. Lame. :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top