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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,286
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,286
Office Version
  1. 365
Platform
  1. Windows
That's right, isn't that what you want?
 

Watch MrExcel Video

Forum statistics

Threads
1,130,112
Messages
5,640,174
Members
417,130
Latest member
Darion2021

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