Cant find Control

T

Todd Huttenstine

Below is a code that programmatically adds an optionbutton to a
userform. This code works fine but when I try to retrieve all the
names of every control, the optionbutton shows up as 0. Its like it
does not have a name.

Dim OB_PriceKPI As MSForms.OptionButton
' Adds New Labels
Set OB_PriceKPI =
KPIWizard.Controls.Add("forms.optionbutton.1", Visible)
With OB_PriceKPI
.Name = "OB_PriceKPI"
.Width = 100
.Height = 18.75
.Left = 36
.Top = 60
'.AutoSize = True
.Font.Size = 8
.Font.Bold = True
.Caption = "Price"
End With

The optionbutton should be called "OB_PriceKPI" as I have specified in
the above code.
Below is the code I use to bring back all the names of every control on
my userform:
For Each ctl In Me.Controls
MsgBox ctl.Name
Next


Last, here is what I am trying to test for with the optionbutton, but
everytime it gets to the If statement, I get an error saying object
required. Again, its like the button does not exist but I just created
it with the 1st code.

Select Case Level
Case 1
If OB_PriceKPI.Value = True Then
KPITargetType = "PP"
Else
KPITargetType = "Feature"
End If
Case Else
End Select



Can anyone help me?
 

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