To select the tabbed page based on the combobox selection:
Private Sub YourComboName_AfterUpdate()
Select Case YourComboName
Case "PageOne"
Me.YourTabControl = 0
Case "PageTwo"
Me.YourTabControl = 1
Case "PageThree"
Me.YourTabControl = 2
Case Else
Me.YourTabControl = 0
End Select
End Sub
Notice that the Tabbed Page index is Zero-based. The first page's
value is 0, the second is 1, etc.
I have recently run into a situation where I had to add pages to a
tab and the logical order of the pages changed the page indexes.
Because of that, I'm moving away from using indexes for working with
tabs. For instance, in the OnChange event of the tab control, I use:
Select Case Me!ctlTab.Pages(Me!ctlTab).Name
Case "PageOne"
...
Case "PageTwo"
...
End Select
and so forth.
Unfortunately, I can't figure out a way to set the value of the tab
based on the name. The only thing I can think of is a Byzantine
routine that walks through the Pages collection and checks the name,
and then returns the value.
Public Function GetTabValueFromPageName(ctl As Control, _
strPageName As String) As Integer
' returns -1 if strPageName does not exist
' otherwise returns value for strPageName
Dim i As Integer
Dim intReturn As Integer
intReturn = -1
For i = 0 To ctl.Pages.Count - 1
If ctl.Pages(i).Name = strPageName Then
intReturn = i
Exit For
End If
Next i
GetTabValueFromPageName = intReturn
End Function
Am I just missing something that would be much easier?
In any case, with the function above, and if your listbox returns
the name of the tab page, then you could replace the original code
quoted at the top with this:
Private Sub YourComboName_AfterUpdate()
Me!YourTabControl = GetTabValueFromPageName (Me!YourTabControl, _
Me!YourComboName)
End Sub
I'd be delighted to hear that there's an easier way and that I'm
just being obtuse.