(Revised):
Private Sub TabClt1_Change()
Select Case TabClt1
Case 0
' First tab (PageIndex =0) on main form was just
selected...
' Select same index # on subform
Me.NameOfSubformControl.Form.TabClt2= 0
Case 1
Me.NameOfSubformControl.Form.TabClt2 = 1
Case Else
MsgBox "Unexpected value: " & TabClt1
End Select
End Sub
1)
The message box appeared however.
Then the PageIndex of the page being selected must be something other than 1
or 2. PageIndex numbers start with 0 so what you refer to as "page1"
probably has an index number of 0 (my bad). PageIndex numbers appear in the
property sheet for the Tab control. The code has been revised to reflect
this. Message box will also display the "unexpected" index number now.
2)
...Case 1 and 2 look the same in your code. Is this correct?
Nope. Corrected
3)
I also tried this:
Me.Tab3.Form.TabClt2 = 1
....Tab3 is the name of the first tab (Page 1) on the subform
And got the error message: Compile error. Method or data memeber not
found. ".
Well, if Me is the main form, and the main form doesn't have a control named
Tab3 **, an error message would be expected.
** The main form doesn't have a control named Tab3 because 1) its on the
subform and therefore part of the subform's Control collection and 2) a tab
control page/tab isn't considered a control anyway (see #3 below).
A couple other things worth mentioning:
1) Controls on a Tab control are referenced as if they are simply part
of the underlying form. The fact that they are on a tab control has no
effect on coding. There is no extra complexity involved.
2) The same is *not* true for subforms. To refer to a control on a
subform, you have to reference the subform and you can't refer to subforms
by their name, you have to use the name of the control that contains the
subform.
"How to Refer to Form and Subform properties and controls"
http://mvps.org/access/forms/frm0031.htm
3) Tabs/Pages on a Tab Control can be referenced in 2 ways: by PageIndex
or by the Name (not Caption) of the page.
- The "Value" property of a TabControl (the default property) reflects
the PageIndex value of the currently selected tab.
- It might help to think of the TabControl's Change event as an
AfterUpdate event since the TabControl's value already reflects the new
value, not the page you've just left.
- The first, leftmost tab will always have a PageIndex of 0. If you
physically move/add/delete tabs, the PageIndex values will be automatically
renumbered from 0 to (Pages.Count - 1), left-to-right.
Both of these would display the PageIndex value of the selected tab:
Msgbox = Me.TabCtl1
Msgbox = Me.TabCtl1.Value
Both of these would set the Tab control to the "first" page,
regardless of its name:
Me.TabCtl1 = 0
Me.TabCtl1.Value = 0
The following would display the Name of the currently selected tab:
MsgBox Me.TabCtl1.Pages(Me.TabCtl1.).Name
The following would set the Tab control to the tab named "PageOne":
Me.TabCtl1 = Me.TabCtl1.Pages("PageOne").PageIndex
Note: these last 2 examples would be the only time the Name property
of a Tab/Page would be of any practical use.
HTH,