Getting type mismatch in for each statement

Posted on 2012-09-19
Last Modified: 2012-09-19
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
Question by:leachj
    LVL 77

    Accepted Solution

    You have used different syntax in your two 'For Each' structures.
    I would think the second one is correct.

    Author Comment

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

    LVL 29

    Expert Comment

    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.

    Author Comment

    Thanks for the tip.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    C# primary key 9 46
    Table Relationships for Linked Tables 2 13
    Subform Link field 13 20
    Open Args 16 23
    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now