PDA

View Full Version : Varied Quantity of Option Buttons



msretenovic
2005-01-26, 08:38 PM
Hi all,

I have a question for y'all. I'm working on a routine right now where I don't necessarily know how many options are going to be available. I also need these options to be available via option buttons.

Is there a way to place option buttons on a form programatically? :screwy: I know, but it would help me out a lot if it were possible.

I would prefer to NOT use a drop down list for this if possible.

Thanks for any help you can offer.

Ed Jobe
2005-01-26, 09:17 PM
You can add them programatically to an object's Controls collection. Use the Add method. Objects that have a Controls collection are the UserForm, or the Frame and Page controls.

msretenovic
2005-01-26, 09:20 PM
You can add them programatically to an object's Controls collection. Use the Add method. Objects that have a Controls collection are the UserForm, or the Frame and Page controls.
That is the kick I needed. Thanks Ed.

Jeff_M
2005-01-26, 09:29 PM
Here's how to add an optionbutton....you'll need to allow for placement on the form, the button's name, as well as the number of existing buttons. And since only 1 option can be selected at a time in a group, you may want to go with checkboxes (togglebutton) in place of option buttons. This code is within the code for the form....

Dim mycontrol As OptionButton
Set mycontrol = Me.Controls.Add("forms.optionbutton.1", "Option1")
mycontrol.Caption = "My First Button"

msretenovic
2005-01-26, 09:32 PM
Here's how to add an optionbutton....you'll need to allow for placement on the form, the button's name, as well as the number of existing buttons. And since only 1 option can be selected at a time in a group, you may want to go with checkboxes (togglebutton) in place of option buttons. This code is within the code for the form....

Dim mycontrol As OptionButton
Set mycontrol = Me.Controls.Add("forms.optionbutton.1", "Option1")
mycontrol.Caption = "My First Button"
This helps greatly. And as far as toggle vs. option, the option is the one I need. I only want one option selected at any given time. Thanks!!!!