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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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
 
Upvote 0
thanks to you both.

Norie, Your suggestion will make the code run ONLY on the page of the multipage that is currently showing. Correct?
 
Upvote 0
That's right, isn't that what you want?
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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
Back
Top