Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2012-12-20
12
465 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)
ID: 38710690
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
ID: 38710747
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)
ID: 38710761
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 75
ID: 38710810
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
ID: 38710824
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
ID: 38710843
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
 
LVL 47

Expert Comment

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

Author Comment

by:wlwebb
ID: 38711000
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
ID: 38711056
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
ID: 38711133
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
ID: 38711214
Fyed
That answered the question of How.......
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38711229
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

829 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