Solved

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

Posted on 2012-12-20
12
471 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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Many to Many From without subform 11 78
How to save an Unbound Text Box to a field on the Table in its After Update event. 6 61
MS ACCESS VBA FORMATTING 9 59
MS Access query 16 54
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

738 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