Help: Multiple Checkboxes (, naming and visibility)

  • Thread starter Thread starter Clinton M James
  • Start date Start date
C

Clinton M James

Hey gang,

I am having a hell of a time trying to work out how to fix my checkbox
needs.

I have a form (UserForm2) which I could now work out how to add checkboxes
to whilst the program was running so i added them to the user form itself.

I have 75 of them. I have overlapped them so I have 3 per line side by side
so people can choose any one or all of three options for each line.

Because the variable name for the objects is a straightforward variable, I
am now finding I cannot address each of these in the program such as I would
if I could in an arrange. Eg I have to address checkbox1 rather than
checkbox(1). The latter would be good in arrays, even if you couldaddress
the names such as Checkbox("Checkbox1")

So I a was wondering how i would address each out.

I need to make all checkboxes invisible except for ones that relate to lines
irequire. Lines are determined by how many lines of reference numbers are
put into userform1.

I also require each series of 3 checkboxes names to the reference number.
Therefore only every 3 hasit's label populated.

Anybody able to point me in the right direction?

I have read some things but it's lost me and I assume because my level of
programming is more intermediate than advanced and I come from the old basic
and pascal days, therefore objects aren't my forte.

Help is appreciated and thank you in advance.
 
You could go through the controls collection:

Dim iCtr as long
for iCtr = 1 to 75
msgbox me.controls("checkbox" & ictr).value
next ictr
==============

Same thing with the visibility stuff
Dim NumberOfLines as long
dim iCtr as long

numberoflines = 8
for ictr = (numberoflines * 3 + 1) to 75
me.controls("checkbox" & ictr).visible = false
next ictr
 
Hi Dave,

Thanks for trying to help but I am still having problems.

The method you sggest doesn't seem to have an option to change the captions
and even if itdid i can't get it to work as it is.

I have 2 userforms and these are in the second userform.

Is there a special place i should put my code>

What happens is I have it get a list of numbers from a textbox in
userform1... then when a person clicks, it will grab each line from the
textbox and split each line into its own part of an array.

For every third checkbox in userform2, i want to change the caption to the
name in the digits in the corresponding array, providing the array has a
value.
If the arrays cease to have a value at some point, i needthe remainder of
checkboxes invisible.

I think my main problem besides the lack of a caption option is that I am
putting code into thewrong part.

I playedaroundand put a sub into Userform2 and I could not call it from a
sub in Userform1

how i load userform2 is by declaring userform2.show

I may be doing this wrong too.

Help is very appreciated if it is possible.
 
You can change 75 captions by using something like:

Dim iCtr as long
for iCtr = 1 to 75
me.controls("checkbox" & ictr).caption = "capt" & ictr
next ictr

I think I'd have an Ok button somewhere on the form and put the code that
hides/shows the checkboxes in that button's click event.

I'm not sure how you get the name in the digits in the corresponding array, but
you could loop through every third checkbox like:

Dim iCtr as long
for iCtr = 3 to 75 step 3 'start with the 3rd checkbox
me.controls("checkbox" & ictr).caption = "whatever caption you need"
next ictr

And to hide/show the checkboxes, you could use:

Dim SomeNumber as long
somenumber = 15 'show the first 15
for ictr = 1 to 75
me.controls("Checkbox" & ictr).visible = cbool(ictr <= somenumber)
next ictr

'or if you like
for ictr = 1 to 75
if ictr <= somenumber then
me.controls("Checkbox" & ictr).visible = true
else
me.controls("Checkbox" & ictr).visible = false
end if
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

Similar Threads


Back
Top