Getting type mismatch in for each statement

I am iterating through the pages of a tab control and comparing captions to a combobox.  I get type mismatch error in the for each statement.  I use a button to hide or show tabs.
How do I get rid of it?

Dim tctl As Control
Dim tpage As Page
Set tctl = Me.TabCtlMain

If Me.btnShowHideTabs.Caption = "Hide Inactive Tabs" And Me.cmbPresponsible <> "" Then
    Me.btnShowHideTabs.Caption = "Show All Tabs"
        Select Case Me.cmbPresponsible
            Case "Mother"
                For Each tpage In tctl
                    If tpage.Caption <> "Mother's Info..." Then tpage.Visible = False
                Next tpage
           End Select
    Me.btnShowHideTabs.Caption = "Hide Inactive Tabs"
    For Each tpage In Me.TabCtlMain.Pages
        If tpage.Visible = False Then tpage.Visible = True
    Next tpage
End If
Who is Participating?
peter57rConnect With a Mentor Commented:
You have used different syntax in your two 'For Each' structures.
I would think the second one is correct.
leachjAuthor Commented:
I see it now, I left off the .pages for tctl

Rather than making tab pages visible and invisible, just set the Style property to NONE and the BackStyle property to TRANSPARENT
Then you can use either
Me.NameOfTabControl.Value="number which refers to the page index"
to go to the page you want.

I like to set Style property to NONE by code so that when I go into design mode, I can still see the tabs and easily switch to the different pages.  In the form's OnLoad event, add Me.NameOfTabControl.Style=2

The other thing that I do in the design view is set the style to Buttons.  This just makes it look cleaner in that mode.  Once you go to your Form view it will be set to NONE because of your OnLoad event.
leachjAuthor Commented:
Thanks for the tip.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.