Dynamic Optionbutton Captions

W

WizOfAus

Hi group,

WinXP Pro
Office 2003

I have created a userform with a frame and 22 optionbuttons. I have
made all optionbuttons hidden (visible=false). What I need to do is
when the form is shown to use a range's value as the caption for the
optionbuttons and to also make them visible. Not all buttons will
always be required, that is why I made them hidden when designing.

I have tried several different loops without success. Any help would be
greatly appreciated.

The buttons are named "PlayerOptBut1,
PlayerOptBut2.......PlayerOptBut22"

Here is my last attempt:

rr = Sheets("RND1").Range("A65536").End(xlUp).Row

For i = 2 To rr
ButtonCaption = Sheets("RND1").Range("D" & i).Value & ". " & _
Sheets("RND1").Range("C" & i).Value & " " & _
Sheets("RND1").Range("B" & i).Value

MatchDayForm.TeamListFrame.PlayerOptBut(i).Caption =
ButtonCaption
MatchDayForm.TeamListFrame.PlayerOptBut(i).Visible = True
Next i

Regards

Rob
 
J

Jon Peltier

I don't think you want to include the name of the frame enclosing the option
buttons.

- Jon
 
W

WizOfAus

Hi Jon,

Thanks for the prompt reply.

I tried the following and received this error "Method or data member
not found (Error 461)"
---------------------------------------------------------------------
rr = Sheets("RND1").Range("A65536").End(xlUp).Row

For i = 2 To rr
ButtonCaption = Sheets("RND1").Range("D" & i).Value & ". " & _
Sheets("RND1").Range("C" & i).Value & " " & _
Sheets("RND1").Range("B" & i).Value

MatchDayForm.PlayerOptBut(i - 1).Caption = ButtonCaption
MatchDayForm.PlayerOptBut(i - 1).Visible = True
Next i
---------------------------------------------------------------------

I believe the error is in this part of the code "PlayerOptBut(i - 1)".

Regards

Rob
 
W

WizOfAus

Hi Charles,

That did the trick. Thanks very much for your timely assistance and
also to Jon.
 
J

Jon Peltier

Interesting, I've never included it.

I missed the use of PlayerOptBut(i) instead of Controls("PlayerOptBut" & i).
Answered this morning before the caffeine kicked in.

- Jon
 
J

Jon Peltier

It makes sense that it's faster, since it more directly references the
controls. I'd just never thought of it.

- Jon
 

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