Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I dynamically create an option group in Excel user form 1

Status
Not open for further replies.

barnard90

IS-IT--Management
Mar 6, 2005
73
US
Hi

I have a field in my Excel user form which states the
MARITAL STATUS.
The Marital status can be either MARRIED , UNMARRIED , WIDOWED , DIVORCED .

How can I dyanamically create 4 option buttons with these above names and group them together as one option group which is Marital Status

Whenever the user clicks on one of these 4 optiion buttons , that corresponding value should fo into the MARITAL STATUS field

For example , if the user clicks the MARRIED option in the option group then MARITAL_STATUS = "MARRIED"

How can I create this
Please suggest
 
barnard90,
Can you create the option group at design time and hide/show the control at run time? It would be easier than creating the controls at design time.

CMP

(GMT-07:00) Mountain Time (US & Canada)
 
barnard90,

To create a group of option buttons, put them on some frame and make the frame visible/invisible on fly.

CautionMP,

You meant "...easier than creating the controls at run time.", right?

vladk
 
Could some one please correct my code
I am trying to create 5 option buttons dynamcially in an excel user form

The code for that is as below


Dim optinput
Dim i As Integer
'
Dim optinput() As Control
For i = 1 To 5
Set optinput(i) = UserForm1.Controls.Add("Forms.optionbutton.1", "optInput" & i, True)
'
With Me!optinput
.Visible = True
.Left = Me.Left + i * 20
.Width = 200
.Top = Me.Top + i * 20
.Caption = "Dynamic option" & i
End With
Next
 
barnard90,

Enjoy:

Private Sub CommandButton1_Click()
Dim oMyOption As Control
Dim i As Integer

For i = 1 To 5
Set oMyOption = UserForm1.Controls.Add(bstrProgID:="Forms.OptionButton.1", Name:="MyOption", Visible:=True)
oMyOption.Top = i * oMyOption.Height
oMyOption.Caption = "BLALALA " & Str(i)
Next i

End Sub

vladk
 
vladk

Thanks a bunch for your valuable post
That was really useful

Enjoy your day
 
vladk,
Yeah, Run Time.

CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top