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
How do I get rid of it?
Dim tctl As Control
Dim tpage As Page
Set tctl = Me.TabCtlMain
If Me.btnShowHideTabs.Caption
Me.btnShowHideTabs.Caption
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
For Each tpage In Me.TabCtlMain.Pages
If tpage.Visible = False Then tpage.Visible = True
Next tpage
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Then you can use either
Me.NameOfPage.SetFocus
or
Me.NameOfTabControl.Value=
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=
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.
ASKER
Thanks for the tip.
ASKER
Thanks,
John