Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Control Array

  Asked By: Diem    Date: Dec 19    Category: MS Office    Views: 935
  

I have come up with a problem, and I hope that you can help me. I
need to assign captions to labels based on idexed values is a string
array. Not until I got well into my project did I find out that you
cannot create control arrays in VBA like you can with VB6.
I did find a way to create an array of conrols.

arraySelection(i) = arrayLabel(i)

But when I try to assign a value to the indexed array of controls, I
get a "variable not set" error.
It looks like the control array is loading just fine. Can you please
tell me what I am doing wrong, or a different approach to use. Since
a large part of my VBA project is based on this, I will really have
to make a big step back if I can't fix this.

I know that you are very busy, and I appreciate that you have taken
time to read this.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Cheryl Murphy     Answered On: Dec 19

I'm not sure how your

> arraySelection(i) = arrayLabel(i)

is creating an array  of controls. You'd need to show more code to get an
informed comment.

However, you can assign  references to controls  to variables. I don't see
any reason why those variables can't be in an array.

But, if you want to assign references to different types of controls to the
same array, you'll probably need to make it an array of variants.

You'll also need to use the "set" keyword in any statement that's assigning
references.

 
Answer #2    Answered By: Adalricus Fischer     Answered On: Dec 19

Any "control arrays" you create  in vba  is going to have to be using text in
the name I think. Like "Control-01", "Control-02,.... And so on.

It's not all that difficult and if you writ a function/sub to process them
there is an overhead but not that much I think.

You could for example code...
subControls 1,"OK"

To set  the caption of control  cmdControl-1 to "OK".

Inside of the sub you'd loop around the controls  testing to see if the end
of the name is 1,2,3 whatever. You could add a control type or partial/full
name to that as well.

I agree though. It's a nice feature of VB to be able to create a control
array IMHO.

 
Didn't find what you were looking for? Find more on Control Array Or get search suggestion and latest updates.




Tagged: