Link to home
Start Free TrialLog in
Avatar of leachj
leachj

asked on

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
   
Else
    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
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leachj
leachj

ASKER

I see it now, I left off the .pages for tctl

Thanks,
John
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.NameOfPage.SetFocus
or
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.
Avatar of leachj

ASKER

Thanks for the tip.