Option button detail

  • Thread starter Thread starter Basil
  • Start date Start date
B

Basil

Hiya, I posted a big message the other day... no reply so
I thought I'd split it up.

Anyone know how I can get detail about the radio button
that is pressed inside an option group... i.e. in the VB
can get the button name? If I say activecontrol.name it
gives the name of the group frame. Any ideas? The caption
of the active radio's label is needed too.

If I am wasting my time and it is impossible, please tell
me to give up.

Thanks loads,

Baz
 
Hi Basil,

Here's some code that might help you - the principles are as follows:

The option buttons in an option group are members of the group's controls
collection.

For any control (ctl), an attached label can be found in ctl.controls(0)

This code simply loops through the controls collection of the option group -
builds a string of all control labels and option values, and determines
which was selected. Hopefully you can use this code as a basis for whatever
you really need to do.

Private Sub Command9_Click()
Dim inti As Integer
Dim strX As String
Dim strY As String
For inti = 0 To Me.Frame0.Controls.Count - 1
If Me.Frame0.Controls(inti).ControlType = acOptionButton Then
strX = strX & Me.Frame0.Controls(inti).Controls(0).Caption _
& ": " & Me.Frame0.Controls(inti).OptionValue & vbCrLf
If Me.Frame0 = Me.Frame0.Controls(inti).OptionValue Then
strY = "You selected the button labeled: " &
Me.Frame0.Controls(inti).Controls(0).Caption
End If
End If
Next inti
MsgBox strX & vbCrLf & vbCrLf & strY
End Sub
 
Hi Basil,

Here's some code that might help you - the principles are as follows:

The option buttons in an option group are members of the group's controls
collection.

For any control (ctl), an attached label can be found in ctl.controls(0)

This code simply loops through the controls collection of the option group -
builds a string of all control labels and option values, and determines
which was selected. Hopefully you can use this code as a basis for whatever
you really need to do.

Private Sub Command9_Click()
Dim inti As Integer
Dim strX As String
Dim strY As String
For inti = 0 To Me.Frame0.Controls.Count - 1
If Me.Frame0.Controls(inti).ControlType = acOptionButton Then
strX = strX & Me.Frame0.Controls(inti).Controls(0).Caption _
& ": " & Me.Frame0.Controls(inti).OptionValue & vbCrLf
If Me.Frame0 = Me.Frame0.Controls(inti).OptionValue Then
strY = "You selected the button labeled: " &
Me.Frame0.Controls(inti).Controls(0).Caption
End If
End If
Next inti
MsgBox strX & vbCrLf & vbCrLf & strY
End Sub
 
Back
Top