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

Is there a way to make a control array in the code module? 2

Status
Not open for further replies.
Nov 8, 2002
9
US
Does anyone know how to make a control array in vba? I have a series of 14 part numbers that I need to manipulate through a loop. I know how to make a control array in visual basic just by naming the textboxes the same name. It always produces a popup menu asking if you wish to create a control array. I tried that in vba, and it said that I could not name two things with the same name. It would not give me the option of creating a control array. I thought maybe there would be a Dim statement out there somewhere that I could use to create one, but I don't know the terminology well enough to find it! Please help me if you can!
 
Control Arrays are not supported by VBA. You can create an array of controls and initialize it but each control will have its own set of events.

Dim aryCtl(13) as Textbox
Set aryCtl(0) = txt0
Set aryCtl(1) = txt1
......
Set aryCtl(13) = txt13 Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Or you can make 14 textboxes called part1, part2, and so on, then make a loop

for x = 1 to 14
me.("part" & x) = "Yourtext"
next x --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
Thanks to both of you! I have two groups of textboxes that I need to cycle through an "array". John, your idea worked great. It's too bad that it doesn't work quite like vb, but maybe I can use this anyway. Thanks for your help! On the next array I might try NVSbe's idea. They look like they would work the same. Thank you both so much. I greatly appreciate it!
 
And just to add to the options, check out Access' user-defined collections. You can add, literally, any object to them. So if you wanted, you could add all of the relevant controls to a collection named Part, and reference each control with syntax liekke Part(0), Part(1), Part(2), and so on.
-- C Vigil =)
(Before becoming a member, I also signed on several posts as
"JustPassingThru" and "QuickieBoy" -- as in "Giving Quick Answers")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top