Avatar of Fordraiders
Fordraiders
Flag for United States of America asked on

Deselect all optionbuttons on userform to 0

excel 2010
Userform
Multipage1 control
Page 5

The following code will deselect all the optionbuttons on all pages.
ans also code not owrking just for Page5?

I need just specifically for page 5


' this works but does all the optionbuttons on any page
Dim cCont As Control
     
    For Each cCont In Me.Controls
        If TypeName(cCont) = "OptionButton" Then
            cCont.Value = False
        End If
   Next cCont


' specficially for page 5 but getting error

Dim pg As Pages
Dim ctl As MSForms.Control
Dim OptChecked As String
      Set pg = Me.MultiPage1.Pages(5) ' pages are 0 indexed  <--- error here "type mismatch
    For Each ctl In pg.Controls
              If TypeName(ctl) = "OptionButton" Then
                    ctl.Value = 0
              End If
    Next ctl



Thanks
fordraiders
Microsoft Excel

Avatar of undefined
Last Comment
Fordraiders

8/22/2022 - Mon
Rory Archibald

Dim pg As Page
Dim ctl As MSForms.Control
Dim OptChecked As String
      Set pg = Me.MultiPage1.Pages(4)

note the bold parts. ;)
Fordraiders

ASKER
Still type mismatch on line below


Dim pg As Page
Dim ctl As MSForms.Control
Dim OptChecked As String
      Set pg = Me.MultiPage1.Pages(4)   <-----  Still Type mistmatch on this line
    For Each ctl In pg.Controls
              If TypeName(ctl) = "OptionButton" Then
                    ctl.Value = 0
              End If
    Next ctl
ASKER CERTIFIED SOLUTION
Rory Archibald

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Fordraiders

ASKER
ok great Thanks
Dim pg As MSForms.Page
Dim ctl As MSForms.Control
      Set pg = Me.MultiPage1.Pages(4)
    For Each ctl In pg.Controls
              If TypeName(ctl) = "OptionButton" Then
                    ctl.Value = 0
              End If
    Next ctl


also got this to work...

Dim cCnt As Control
For Each cCnt In Me.MultiPage1.Pages(4).Controls
If TypeName(cCnt) = "OptionButton" Then
cCnt.Value = 0
End If
Next cCnt
Your help has saved me hundreds of hours of internet surfing.
fblack61
Fordraiders

ASKER
Thanks very much !