?
Solved

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

Posted on 2012-12-20
12
Medium Priority
?
476 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
[X]
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
  • 6
  • 5
12 Comments
 
LVL 48

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 48

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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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 48

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 48

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 48

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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