Name of active tab page

D

Douglas J. Steele

The value of the Tab control will be the number of the active page.
(Remember that numbering starts at 0). That means that

Me.TabCtl0.Pages(Me.TabCtl0).Name

should give you the name.
 
T

Tom van Stiphout

On Wed, 12 Aug 2009 06:55:01 -0700, QB <[email protected]>
wrote:

myTab.Value gives you the 0-based index.
myTab.Pages(myTab.Value).Name gives you the name of that tab.

-Tom.
Microsoft Access MVP
 
D

David W. Fenton

myTab.Value gives you the 0-based index.
myTab.Pages(myTab.Value).Name gives you the name of that tab.

After going back to an old project with a tab control where I'd
coded the CASE SELECT for the tab's OnChange event using numeric
values, and realizing I couldn't remember what was what without
commenting them, and then needing to add a new tab before existing
tabs, which thus changed the index values and meant I had to rewrite
the CASE SELECT, I have since changed my OnChange events to use:

Select Case Me!ctlTab.Pages(Me!ctlTab).Name
Case "pgeDetails"
...
Case "pgePictures"
...
End Select

and so forth. It's much easier to work with and is future-proofed,
because it's not dependent on the ordering of the tabs, and also
doesn't need to be commented in order to be easily understood.
 
D

Dale Fye

Dave,

Had the same problem after a client wanted to resequence the tabs.

Now I prefer to use the Caption property. It is easier than using the Name
property since it is readily visible in the form design view while coding.
 
D

David W. Fenton

Now I prefer to use the Caption property. It is easier than using
the Name property since it is readily visible in the form design
view while coding.

I am much more likely to change the caption property than the name
of the tab page name. Also, I frequently use tab controls with tabs
not displayed (and drive the tab with other controls), so that
wouldn’t help.
 
D

Dale Fye

But it is easy to do a search and replace in the VBE, so if I change a tab
caption, I just go into the VBE, search for that text string, and replace as
appropriate.

I also frequently hide my tab captions (at least when the application is
running), but these are always visible in design view. So when I'm writing
code on one screen, all I have to do is look at the design of the form view
to identify the captions of the various tabs. Using your method, you
actually have to click on the tab to ensure you have the correct Name.

Just my 2 cents, I've tried it all three ways (index, Name, and Caption) and
personally find referring to the caption easier. Both when writing, and then
when returning to maintain my code.
 
D

David W. Fenton

I've tried it all three ways (index, Name, and Caption) and
personally find referring to the caption easier.

I am much more rigid about naming controls than I am about assigning
captions, so I'm much more likely to remember the tab control name.

Also, the tab control names show up in Intellisense, but the
captions do not. For me, that constitutes an open-and-shut case for
the superiority of using the tab names instead of the captions.
 

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

Similar Threads


Top