What page?

  • Thread starter Thread starter m.h.dashper
  • Start date Start date
M

m.h.dashper

On a TabControl how can I determine, in code, which tab is active?
I want to click on a tab and be told which page it belongs to.
The OnClick event for the page only triggers when you click on the
body of the page, not the tab.

Martin Dashper
 
On a TabControl how can I determine, in code, which tab is active?
I want to click on a tab and be told which page it belongs to.
The OnClick event for the page only triggers when you click on the
body of the page, not the tab.

Martin Dashper

The value of the tab control itself is the PageIndex property of the
current page. The Change event of the tab control fires whenver you
change pages by clicking a tab.
 
For a TabControl named tabMain:

Me.tabMain.PageIndex
will return the index # of the current page (starting from zero)

PageIndex is the default property of a TabControl, so it can also be stated
as:
Me.tabMain

Sample usage:

Private Sub tabMain_Change()

Select Case Me.tabMain.PageIndex
Case 0
'Do this
Case 1
'Do this
Case 2
'Do this
End Select

*OR* (more readable IMO)

Select Case Me.tabMain.Pages(Me.tabMain.PageIndex).Name
Case "pgData"
'Do this
Case "pgVariables"
'Do this
Case "pgReports"
'Do this
End Select

End Sub
 
Correction:
Value is the default property of a tab control. The value of Value = the
PageIndex of the current Page.

SO: substitute Me.tabMain.Value (or just Me.tabMain) in the 3 places where I
originally wrote Me.tabMain.PageIndex
 
The value of the tab control itself is the PageIndex property of the
current page. The Change event of the tab control fires whenver you
change pages by clicking a tab.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
Thanks a lot Dirk. Problem sorted.

Martin
 
Correction:
Value is the default property of a tab control. The value of Value = the
PageIndex of the current Page.

SO: substitute Me.tabMain.Value (or just Me.tabMain) in the 3 places where I
originally wrote Me.tabMain.PageIndex

Thanks for that George.

Martin
 
Back
Top