adding radio buttons dynamically to option group

  • Thread starter Thread starter Ernest Leong
  • Start date Start date
E

Ernest Leong

Is it possible to dynamically add option buttons to an option group frame?
I'm using the CreateContrtol method to create an option button that I would
like to put into an option group, and I'm getting a "Invalid reference to
the property OptionValue" when I try to set that particular property.

Thanks,
Ernest
 
You can CreateControl only in design view, so most of us don't like that
approach. It will stop you from ever releasing an MDE of your application.

If you want to do it anyway, and you have your form open in design view,
make sure that the option group is the parent of the new option button when
you CreateControl. A stand-alone option button has no OptionValue.
 
I'm getting a "Object does not support this method or property" at the line
for setting the .Parent property below when I try this.
----------------------------------------------------
Dim ctl as Control
Dim opt as OptionButton
' optGroup
Set ctl = CreateControl(frm.Name, acOptionGroup, acDetail, , , 8640, 300,
6180, 6060)
With ctl
.Name = "optGroup"
.Visible = True
.DisplayWhen = 0
.Enabled = True
.Locked = False
.TabStop = True
.TabIndex = 0
.BackStyle = 0
.BackColor = 16777215
.SpecialEffect = 3
.BorderStyle = 1
.OldBorderStyle = 1
.BorderColor = 0
.BorderWidth = 0
.BorderLineStyle = 0
.HelpContextId = 0
.ColumnWidth = -1
.ColumnOrder = 0
.ColumnHidden = False
End With

' begin loop through recordset

' opt
Set opt = CreateControl(frm.Name, acOptionButton, acDetail, , , 9480,
intTopOpt, 260, 240)
With opt
.Name = "opt" & iOpt
.Visible = True
.DisplayWhen = 0
.parent =frm.optGroup
.OptionValue = CInt(rstOptions.Fields("code"))
.Enabled = True
.Locked = False
.SpecialEffect = 2
.BorderStyle = 1
.OldBorderStyle = 1
.BorderWidth = 0
.BorderLineStyle = 0
.BorderColor = 0
.HelpContextId = 0
.ReadingOrder = 0
End With

' lblOpt
Set ctl = CreateControl(frm.Name, acLabel, acDetail, , , 9710, intTop, 4695,
330)
With ctl
.Name = "lblOpt" & iOpt
.Caption = rstOptions.Fields("OptionText")
.Visible = True
.DisplayWhen = 0
.Vertical = False
.BackStyle = 0
.BackColor = 16777215
.SpecialEffect = 0
.BorderStyle = 0
.OldBorderStyle = 0
.BorderColor = 0
.BorderWidth = 0
.BorderLineStyle = 0
.ForeColor = 0
.FontName = "Tahoma"
.FontSize = 12
.FontWeight = 400
.FontItalic = False
.FontUnderline = False
.TextFontCharSet = 0
.TextAlign = 0
.FontBold = 0
.ReadingOrder = 0
.NumeralShapes = 0
.LeftMargin = 0
.TopMargin = 0
.RightMargin = 0
.BottomMargin = 0
.LineSpacing = 0
End With

' end loop throught recordset
 
No, there is not a Parent property to set.

Specify the name of new control's parent as the 4th argument of
CreateControl, i.e.:
CreateControl(frm.Name, acOptionGroup, acDetail, "optGroup", ...
 
Back
Top