Results 1 to 6 of 6
  1. #1
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Step through all optionButtons in a Frame (Word 2000 SR1a)

    I have a userform with a lot of option buttons. These option buttons are grouped in 3 frames on the form.

    I want to iterate across the buttons with a construction like

    <pre> For Each optNextButton in frmMyForm.framMyFrame
    If optNextButton.Value Then
    ' Do something here
    End If
    Next
    </pre>


    I just can't work out the correct syntax to do this <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15> Any suggestions?

    StuartR

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Step through all optionButtons in a Frame (Word 2000 SR1a)

    It should work with a slight modification. <pre>For Each optNextButton in frmMyForm.framMyFrame.Controls</pre>

    Andrew C

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Step through all optionButtons in a Frame (Word 2000 SR1a)

    Andrew,

    I had tried something similar, but since the vba editor didn't offer Option Button properties and Methods for the Control object I thought it wasn't working.

    It's all working fine now <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>

    Thanks <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

    StuartR

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Step through all optionButtons in a Frame (Word 2000 SR1a)

    I'm very nearly there.

    My code now works, but it has multiple loops - one for each frame. It would be much neater if I could go through all the option buttons on the form in one loop and take action based on the GroupName property.

    When I have found a Control on the form, how can I check to see if it is an OptionButton. There is no obvious property of a control that shows what type of control it is, and if I try to access the GroupName property of other controls it generates errors.

    StuartR

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Step through all optionButtons in a Frame (Word 2000 SR1a)

    Hi Stuart,
    Try something like:
    <pre> Dim ctlTemp As Control
    For Each ctlTemp In Me.Controls
    Select Case TypeName(ctlTemp)
    Case "OptionButton"
    'do whatever
    Case Else
    End Select
    Next ctlTemp
    </pre>

    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Step through all optionButtons in a Frame (Word 2000 SR1a)

    > Hope that helps.

    It does more than help. Thank you. That's a well hidden piece of syntax! I now have a (reasonably) neat bit of code to do the job.

    StuartR

Posting Permissions

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