?
Solved

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

Posted on 2012-12-20
12
Medium Priority
?
482 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 49

Expert Comment

by:Dale Fye
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 49

Expert Comment

by:Dale Fye
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 49

Expert Comment

by:Dale Fye
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 49

Accepted Solution

by:
Dale Fye earned 2000 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 49

Expert Comment

by:Dale Fye
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

571 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