What page?

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
 
D

Dirk Goldgar

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.
 
G

George Nicholson

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
 
G

George Nicholson

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
 
M

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.

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

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

Martin
 
M

Martin Dashper

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top