Solved

Access - Tab Form - Trap Form Tab "Name" in a Textbox

Posted on 2012-12-20
12
430 Views
Last Modified: 2012-12-20
Is there a way through VB code to trap a Form's Tab Page Name in a textbox?

If I have a subform on that tab, I am successful in trapping that Subform's Name, but Can I trap the Name of the Tab Page itself?

The following code traps the name of my Tab's Subform.  However in this case this form is on the Tab Control Page3



Forms![frm_Inv]![frm_MiscInvSub02].Form![txtTest] = Forms![frm_Inv]![frm_MiscInvSub02].Name
0
Comment
Question by:wlwebb
  • 6
  • 5
12 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
If you are talking about the caption that appears in the Tab, you would use a syntax similar to:

Me.tabControlName.Pages(Me.tabControlName).Caption

If you have not assigned the tab a caption, then the "Name" property would be:

Me.tabControlName.Pages(Me.tabControlName).Name

In case you don't know, you might try:

NZ(Me.tabControlName.Pages(Me.tabControlName).Caption, Me.tabControlName.Pages(Me.tabControlName).Name)

This later method would return the caption (if it exists) or the name of the currently selected tab in your tab control.  Make sure to replace "tabControlName" with the actual name of the tab control (not the individual pages).
0
 

Author Comment

by:wlwebb
Comment Utility
The one I am "attempting" is

Me.tabControlName.Pages(Me.tabControlName).Name

I have named the TabControl itself "TabCtl_InvParts"

The "Name" on the Property Sheet is Page2 which is Page Index 2 with a Blank Caption(not interested in trapping the Caption"

So I attempted
Me.TabCtl_InvParts.Pages(Me.TabCtl_InvParts).Name

It doesn't like that..........
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
what are you doing with that value? and where is that coming from?

You may have to use:

Forms![frm_Inv]!TabCtl_InvParts.Pages(Forms![frm_Inv]!TabCtl_InvParts).Name
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Try this syntax:

Me.TabControlName.Pages(Me.TabControlName.Pages(Me.TabControlName).Name).PageIndex

This will give you the current PageIndex ... 0,1,2 ect
0
 

Author Comment

by:wlwebb
Comment Utility
Creating a generic code that will make Visible = False a whole slew of Tabs after the subform on each tab is completed.  So that I don't have to code each tab number within a process then I was going to do something like:

Dim lngPageNbr as Long, i as integer
i=1
For i = i to GetAllEstimFormCount()
Parent("Page" &  i).Visible=False
Next
0
 

Author Comment

by:wlwebb
Comment Utility
DataMx,

Thank you.  Tried that and it always bombs on the TabControlName at the very end of the code...
Pages(Me.TabControlName).Name).PageIndex

I Changed it to the "Name" of my Tab_Ctl_Inv and it still bombs.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
Can you copy and paste the exact code that you are using?
0
 

Author Comment

by:wlwebb
Comment Utility
Forms![frm_Inv]![frm_MiscInvSub02.Form![txtTest]] = Forms![frm_Inv]![TabCtl_Inv].Name

When I do the above, my text box gets the info "TabCtl_Inv"  Which is the TabControl's Name....  Now I need it to go the next step and get the ActiveControl's Page Name.

Maybe there simply isn't a way to get it without hard coding each and every Page Name in my overall code.
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
Comment Utility
So, you are trying to fill the txtTest field, on the subform with the name of the tab that the control is on.  Is that correct?

Forms![frm_Inv]![frm_MiscInvSub02].Form![txtTest] = Forms![frm_Inv]![TabCtl_Inv].pages(Forms![frm_Inv]![TabCtl_Inv]).Name
0
 

Author Comment

by:wlwebb
Comment Utility
Yes,,, that is what I am attempting....

That code was awfully close....  But it is giving me the result of the Page Name of the Tab I am coming from, not the one Loading....

I was putting that in the On_Load event of the Form.  If I move it somewhere that executes after the form is loaded I guess that will in fact work  Tried it by putting a command button on the form once it is open and it does work.

So, Is there a way to leave it in the On_Load event????????
0
 

Author Closing Comment

by:wlwebb
Comment Utility
Fyed
That answered the question of How.......
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
Try putting it in the Change event of the tab control (not the page) of the main form.

 I usually don't even load subforms until the tab they are on gets the focus.  The code I use for working with tabs looks something like:
Private Sub TabCtl_Inv_Change

    'I use the caption property because I can see what is on the captions
    Select Case me.tabCtl_Inv.pages(me.TabCtl_Inv).Caption
         Case "Tab 1 Caption"

         Case "Tab 2 Caption"

              'if the subform is not loaded, load it
              if me.subTab2Subform.SourceObject = "" Then
                   me.subTab2Subform.SourceObject = "frm_MiscInvSub02"
              endif

              'assign the Name of the tab to txtTest if it is a new record
              If me.frm_MiscInvSub02.form.NewRecord then 
                  me.frm_MiscInvSub02.form.txtTest = me.[TabCtl_Inv].pages(me.[TabCtl_Inv]).Name

                  'but in reality, with this method, since you already know the tab that has the focus,
                  'you could use
                  me.frm_MiscInvSub02.form.txtTest = "Tab 2 Name"
              End If
              
         Case "Tab 3 Caption"

         Case Else
             msgbox "Invalid tab"
    End Select

End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now