Results 1 to 3 of 3
  1. #1
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    254
    Thanks
    6
    Thanked 1 Time in 1 Post

    Control Array Selected (VBA/Excel/2003)

    I know I have done this before but cannot remember the syntax.

    I have 8 option buttons in a frame. I need to capture the caption from the selected button for the next step.
    Alan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Control Array Selected (VBA/Excel/2003)

    VBA in the Office apps doesn't have control arrays as far as I know - they are a feature of VB6.

    You'll have to test which control is selected in a series of If statements or in a loop, if you have numbered the control names consistently:

    Dim strCaption As String
    Dim i As Integer

    For i = 1 To 8
    If Me.Controls("OptionButton" & i) = True Then
    strCaption = Me.Controls("OptionButton" & i).Caption
    Exit For
    End If
    Next i

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Control Array Selected (VBA/Excel/2003)

    Not sure what you mean by "selected." Your picture shows design-time, not run time. However, you can iterate through the option buttons in the frame. HTH --Sam
    <pre> Dim c As Control
    For Each c In fraMedicalCoverage.Controls
    If TypeOf c Is msforms.OptionButton Then MsgBox c.Caption
    Next c
    </pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •