Results 1 to 9 of 9
  1. #1
    MTM is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    20

    Nested forms with Tab Controls

    I am trying to change the Page caption Text on two levels of nested forms with Tab Controls.
    Form1 (main form) contains Tab control with 2 tabs
    Form2 with a set of Tabs is placed in one of Form1 tabs to create a 2nd level for each of the Tabs in Form1.
    Form3 is located on one of Form2's Tab Control pages.
    The below code is successful at allowing me to update Page captions at Form1 level (it is an click event on Form3). I cannot reference the 2nd level tab Control TabCtl2, (TabCtl1 is the first level's Tab Control) to allow changing page text in this 2nd level Tab control. I have tried many referencing schemes... none seem to work.
    Any help out there would be appreciated.
    Mike

    Private Sub Command144_Click()
    Dim frm As Form
    Dim Txt As String
    Dim tabCtl As TabControl, pg As Page, intPageNum As Integer

    'You must first set the focus to the Control holding the subform
    Forms!Form1.SetFocus
    Forms!Form1!Form2.SetFocus
    'Forms!Form1!Form2!Form3.SetFocus

    Set frm = Screen.ActiveForm

    Debug.Print frm.Name, frm.Controls("TabCtl1").Name
    Set tabCtl = frm.TabCtl1

    ' List all controls for each page on the tab control in the Debug window.
    For Each pg In tabCtl.Pages
    intPageNum = intPageNum + 1

    Txt = pg.Name
    'LabelTxt = rs.Fields(Language)
    LabelTxt = "Test_10"
    frm.Controls(Txt).Caption = LabelTxt 'write to form label



    Debug.Print pg.Name, frm.Name, frm.Controls(Txt).Caption

    Next pg
    End Sub

    Debug.Print for above code

    Form1 TabCtl1
    Page2 Form1 Test_10
    Page3 Form1 Test_10

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe you would post your dB?? Not sure I understand what you have......

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I agree with Steve --we need to see the database. You might also consider giving your forms and controls more meaningful names.

  4. #4
    MTM is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    20
    My db is large and complex. I have attached a very simplified version that illustrates what I am trying to do. Open Form1 and and click the Select Product button.

    Hopefully, my original description and this db will help understanding.
    Mike
    Attached Files Attached Files

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why do this?

    Set Caption property of Page2_2 then open Form1 and test this in VBA Immediate Window:

    ?Forms!Form1.Form2.Form.Page2_2.Caption

    Looping subform controls not something I've ever had to do.

    I don't think using Screen.ActiveForm will be helpful because active form is the main form, not subform. Setting focus to a subform container does not make that the active form. Probably have to set an object variable to the subform.


    Last edited by June7; 05-30-2020 at 02:31 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    My suggestion is that, if this smaller database is a reflection of your complex database, then normalization would seem a good staring point. You'll also find that spaces and/or special characters (#) will cause syntax issues at some point. Better to stick with no spaces nor special characters in your field and object names. I agree with June re Screen.ActiveForm.
    Seems to be a paint-line type process(es) involved.

  7. #7
    MTM is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    20
    June7, The purpose of looping through the nested Tabs is to change language on the form by replacing existing caption with text from a table that converts to another language

    How do I Set Caption property of Page2_2? This is the problem... the methods I have tried to reference Page2_2 do not work.
    Please give example... or better yet... add it to the db I uploaded
    Thank you,
    Mike

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I provided example of full path reference to Page2_2. It worked for me.

    If you want to change captions of tab pages on Form2, why is code behind Form3?

    Consider:
    Code:
    Private Sub Command144_Click()
    Dim LabelTxt As String
    Dim intPageNum As Integer
    For intPageNum = 0 To Forms!Form1!Form2.Form.TabCtl2.Pages.Count - 1
        'LabelTxt = rs.Fields(Language)
        LabelTxt = "Test_10"
        Forms!Form1!Form2.Form.TabCtl2.Pages(intPageNum).Caption = LabelTxt   'write to form label
        Debug.Print Forms!Form1!Form2.Form.TabCtl2.Pages(intPageNum).Caption
    Next
    End Sub
    or
    Code:
    For intPageNum = 0 To Me.Parent.Form.tabCtl2.Pages.Count - 1
        'LabelTxt = rs.Fields(Language)
        LabelTxt = "Test_10"
        Me.Parent.Form.tabCtl2.Pages(intPageNum).Caption = LabelTxt   'write to form label
        Debug.Print Me.Parent.Form.tabCtl2.Pages(intPageNum).Caption
    Next
    

    Should have Option Explicit in header of every code module. Force this as default in new modules: in VBE > Tools > Options > check Require Variable Declaration

    Last edited by June7; 05-30-2020 at 02:57 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    MTM is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    20
    Thank you very much... your code worked well for me and I understand why it did not work before.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to reference controls on sub forms
    By mdavid in forum Forms
    Replies: 8
    Last Post: 11-07-2017, 02:37 AM
  2. Compare controls of two forms
    By newbieX in forum Programming
    Replies: 7
    Last Post: 10-07-2014, 09:06 AM
  3. Referencing Controls on Forms
    By cbh35711 in forum Access
    Replies: 7
    Last Post: 04-05-2012, 09:04 PM
  4. Controls in forms and subforms
    By donnan33 in forum Access
    Replies: 2
    Last Post: 01-05-2012, 10:29 AM
  5. Filling controls on two forms
    By recon2011 in forum Forms
    Replies: 3
    Last Post: 09-01-2011, 01:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums