CheckBoxes on MultiPage

J

John Wilson

Initially I was setting the values of a group of CheckBoxes on a UserForm
via the following code (and it worked well):

Private Sub Binary2CB()
cbResult = "0011001101" ' (for test purposes)
Dim x As Integer
For x = 1 To 10
If Mid(cbResult, x, 1) = 1 Then
Userform1.Controls("CheckBox" & x).Value = True
End If
Next x
End Sub

I've since moved the CheckBoxes onto a Mulitpage control
on the same UserForm.
How can I modify the code above to make this work?
(I've tried a number of different manipulations but can't seem to find the
right combination).

Thanks,
John
 
B

Bob Phillips

Have you tried

Userform1.MultiPage1.Pages(0).Controls("CheckBox" & x).Value = True

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
J

John Wilson

Bob,

No, I hadn't tried that.
Your suggestion didn't work until I removed the UserForm1 reference but
you did get me started in the right direction.

The following:
MultiPage1.Pages(0).Controls("CheckBox" & x).Value = True
Did work though.

There were actually 25 CheckBoxes across the 3 pages on that MultiPage
so my final code ended up looking like this:

Private Sub Binary2CB()
cbResult = "0100000000001110000000010" ' (For test purposes)
Dim x As Integer
For x = 1 To 25
If Mid(cbResult, x, 1) = 1 Then
If x < 12 Then
MultiPage1.Pages(0).Controls("CheckBox" & x).Value = True
Else
If x > 21 Then
MultiPage1.Pages(2).Controls("CheckBox" & x).Value =
True
Else
MultiPage1.Pages(1).Controls("CheckBox" & x).Value =
True
End If
End If
End If
Next x
End Sub

Thank you very much for your help,
John
 
D

Dick Kusleika

John

Did you change the name of your userform? I didn't need to preface the
control reference with the mulitpage, so it sounds like you may have two
userforms. You didn't say what error you were getting, if any, so it's hard
to say if that's it. If the code is in the userform's code module, you
should be able to use

Me.Controls("CheckBox" & x).Value

Me is a keyword that refers to the class it's contained in, in this case the
userform. If you ever happen to change the name of the userform, Me will
still work.
 
J

John Wilson

Dick,

Yes, I did change the name of the UserForm to "OCMC".
Bob gave me this:
Userform1.MultiPage1.Pages(0).Controls("CheckBox" & x).Value = True
which I changed to this:
OCMC.MultiPage1.Pages(0).Controls("CheckBox" & x).Value = True
and it didn't work.
The error that the above gives is "Object doesn't support this property or
method"

The following did work though:
MultiPage1.Pages(0).Controls("CheckBox" & x).Value = True
I tried this and it also worked:
Me.MultiPage1.Pages(0).Controls("CheckBox" & x).Value = True

All the code is in the UserForm module.
Looking at it again, it really doesn't make sense why if "Me" works
and no preface works, why wouldn't "OCMC" (the actual name of
the UserForm) wouldn't work.

Again, Bob did steer me in the right direction ("Pages(0)" was the
critical part that I was missing) and I did get it to work.

Thanks,
John
 

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