Getting type mismatch in for each statement

Posted on 2012-09-19
Medium Priority
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
  • 2
LVL 77

Accepted Solution

peter57r earned 1500 total points
ID: 38414568
You have used different syntax in your two 'For Each' structures.
I would think the second one is correct.

Author Comment

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

LVL 29

Expert Comment

ID: 38414802
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

ID: 38414822
Thanks for the tip.

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

862 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