Minor issue while looping throgh controls

birdieman

Well-known Member
Joined
Jan 13, 2016
Messages
551
I am trying to loop through all textboxes on the "active" page of a multipage userform and change the backstyle on each one:

Code:
Dim cCont As Control
    For Each cCont In Me.MultiPage1.ActivePage.Controls
        If TypeName(cCont) = "TextBox" Then
            .BackStyle = fmBackStyleTransparent
        End If
    Next cCont
End Sub

I am getting a compile error. What do I need to put in front of ".Backstyle....." to make it work? Also, is "ActivePage" correct?

thanks
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
You need cCont in front of .BackStyle.

As for ActivePage, there's no such thing - to refer to the active page of a multipage control you can use Me.MultiPage1.Pages(Me.MultiPage1.Value).
Code:
Dim cCont As Control

    For Each cCont In Me.MultiPage1.Pages(Me.MultiPage1.Value).Controls
        If TypeName(cCont) = "TextBox" Then
            cCont.BackStyle = fmBackStyleTransparent
        End If
    Next cCont
 

birdieman

Well-known Member
Joined
Jan 13, 2016
Messages
551
thanks to you both.

Norie, Your suggestion will make the code run ONLY on the page of the multipage that is currently showing. Correct?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
That's right, isn't that what you want?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,748
Messages
5,855,440
Members
431,733
Latest member
bestassignmentexpert789

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top