Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag 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
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

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

note the bold parts. ;)
Avatar of 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
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Thanks very much !