Calling an Object using variables (What am I doing wrong????)

S

Superman

I was wondering if someone out there might know how I would be able to
do the following:

I have 3 ComboBoxes and 3 Labels that are named as follows

Label_1
Label_2
Label_3

ComboBox_1
ComboBox_2
ComboBox_3

I am trying to create a subroutine to go through a loop from 1-3 and
hide both the comboboxes and labels, but for some reason I can not use
variables to call an object. Any ideas how I could make this work?


here is my subroutine so far


sub removeitems ()

dim counter as integer
dim tag1 as string
dim tag2 as string
dim ctl as control

counter = 1
tag1 = "ComboBox_"
tag2 = "Label_"

do until counter = 3

ctl = tag1 & counter (I have also tried using Set ctl =)
ctl.visible = false
ctl = tag2 & counter
ctl.visible = false

counter = counter + 1

loop

end sub
 
D

Dave Peterson

Controls on a userform?

Dim iCtr as long
for ictr = 1 to 3
me.controls("label_" & ictr).visible = false
me.controls("combobox_" & ictr).visible = false
next ictr
 

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