Tab control and events.

M

Mike

I am having a little trouble with my Tab Controls.
I want to make it so that when I click a tab label (such
as "Hello" in the below example), I want some code or a
macro to be executed. However, the on click event for a
page does not include the actualy tab, so the tab itself
will not activate an event when it's clicked. I was
informed about an on change event that could work, but I
need to be a little more specific than that. Take the
following example.
______ ________ ____________
/Hello \/Good Bye\/Good Morning\_________________

This is a fictional example:
I am currently in the "Hello" tab, and a text box
says "Hello, Mike". Now, I click on the Good Bye tab, so
it can display "Good Bye, Mike". The On Change event is
activated, but how do I know whether or not the user
clicked on the "Good Bye" or "Good Morning" tab? I want
the text box to display "Good Bye, Mike" or "Good Morning,
Mike" depending on which tab is selected.
Is there a property for the tab control, such as
TabControl.CurrentPage or something?

Any further help would be greatly appreciated.
 
P

PC Datasheet

Mike,

Each page in a tabcontrol has a PageIndex property (0 based). You need to test
for the PageIndex to determine what tab you clicked on.
 
G

George Nicholson

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

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

Sample usage:

Note: tab_Change event NOT page_Click

Private Sub tabMain_Change()

Select Case Me.tabMain.Value
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.Value).Name
Case "pgData"
'Do this
Case "pgVariables"
'Do this
Case "pgReports"
'Do this
End Select

End Sub
 

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