We help IT Professionals succeed at work.

Deselect all optionbuttons on userform to 0

Fordraiders
Fordraiders asked
on
454 Views
Last Modified: 2012-05-30
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
Comment
Watch Question

Rory ArchibaldGrand Poobah
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011

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

note the bold parts. ;)

Author

Commented:
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
Grand Poobah
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Author

Commented:
Thanks very much !

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.