Change Active Tab 2013 VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mashman
    New Member
    • Dec 2013
    • 4

    Change Active Tab 2013 VBA

    Hello,

    I am using Access 2013.

    I have Navigation Tabs when I click on a button in the form below the Tab I want to move to another Navigation tab.

    I have been able to successfully Set focus from the command button in the form to the Tab I want, but I cannot get it to make that tab/page the one that is displayed.

    Code:
    //navViewOrder is the tabs name I want to go to.
    //NavigationControlSales is the the tab control name of which NavViewOrder is the 3rd tab.
    
    
    Private Sub cmdSaveNext_Click()
        Me.Parent.navViewOrder.Setfocus = True //This works
        Me.Parent.NavigationControlSales = 2 // I get Error 440 You can't assign a value to this object.
        
    End Sub
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    mashman:
    So that we are on the same page:

    - You have a form.
    - On that form you have inserted the Navigation Control.
    - In the Navigation Control you have a series of buttons/tabs that either run along the top, down the left side or both
    - You are currently in a tab named ?
    - You would like to move to a tab named "navViewOrd er"

    Just as an example this:
    [imgnothumb]http://bytes.com/attachment.php? attachmentid=73 84[/imgnothumb]

    -->[2013-12-19]---> Because I don't want to lose this information about Navigation Subforms I thought, where better than to store it here? The information is a tad eaiser to find now with a search; however, still no really good explanations:

    Here's the deal with the navigation control:

    1) Unless renamed, the default name for the navigation control is "NavigationSubf orm" and we need to confirm this or confirm the name of the "NavigationSubf orm" control.
    - To confirm this, open your form in design view.
    - Show the properties dialog for any control on the form OTHER than the "NavigationSubf orm" - selct the parent form header or the parent form details.
    - Now in the propeties box, in the dropdown, you should see either the default name of "NavigationSubf orm" or the name you gave it.

    2) Every time you click on a navigation button/tab (NavBtn), or navigate to it using VBA, the current form is unloaded the form associated with the newly selected NavBtn is loaded. Thus, any values on the form you were on are lost unless you pass them in the calling code or store the value in a global type variable.
    - in effect, this is a late binding tab form without the benfit of keeping the values from the other tabs.
    - the positive, every time the form loads, it requeries and runs the onload/open/etc events.

    3) It doesn't matter what NavBtn you click on, the form associated with that control is loaded and you refer to it as follows
    - from the parent: me.NavigationSu bform.Form![boundcontrolnam e]
    - from within the loaded form me.[boundcontrolnam e]

    4) To go from one navigaton control to another, you need something like this:

    For a simple movement between forms, then ignore the ">" redirect as given in the link, just follow:

    So I'm on a differenet form and have a command button or perhaps one of the controls has an on click for details so I need to go to the form "frm_qry_asset_ inventory_logbo ok" for the details then:

    Code:
    DoCmd.BrowseTo objecttype:=acBrowseToForm, _
       objectname:="frm_qry_asset_inventory_logbook", _
       PathtoSubformControl:="frm_navigation.navigationsubform", _
       WhereCondition:="Inventory_pk = " & [Inventory_pk]
    The "objectname " is the name of the FORM that is loaded by clicking on the NavBtn, NOT the name of the NavBtn
    The "WhereCondition " is a valid SQL "WHERE" clause Select.... WHERE("Inventor y_pk = " & [Inventory_pk]) this sets the filter for the loaded subform.

    5) to set the focus on a control in the newly loaded subform it is a two step process you will need somethin like this:

    so we move to the form "frm_loanaccoun ts" that loads in the navigationsubfo rm control and we want to set focus to the combobox for new customers named "zcbo_newcustom er"
    Code:
    DoCmd.BrowseTo objecttype:=acBrowseToForm, _
       objectname:="frm_loanaccounts", _
       PathtoSubformControl:="NavigationForm.navigationsubform"
       With Forms.Item("NavigationForm").navigationsubform
          .SetFocus
          !zcbo_newcustomer.SetFocus
       End With
    NOTE THE BANG for the control

    >that should cover a few things and I hope is useful for those hunting for information about the ACC2010 and later Navigation Subform Control
    Attached Files
    Last edited by zmbd; Dec 19 '13, 11:27 PM. Reason: [z{saved my info}]

    Comment

    • mashman
      New Member
      • Dec 2013
      • 4

      #3
      1) THANK YOU - You are correct this information is a really hard find. I must have read over 500 posts over the last 2 weeks trying to do this. I think they are all talking about the old Tabbed forms more commonly used in pre 2010 access.

      2) GOOGLE SEARCH TIP =>2010 - I found Google was full of lots of pre Access 2010 clutter as it was near impossible to exclude using keywords, but if you use advance search and filter results only in last 2 years, you get a higher amount of results regarding access 2010.

      3) PIC - Yes your example pic is the layout I am working with.

      4) WORKING -

      Code:
      Private Sub cmdSaveNext_Click()
          DoCmd.BrowseTo ObjectType:=acBrowseToForm, _
          ObjectName:="CustomerOrderOverview", _  //This my form attached to Navigation tab I want to move too.
          PathToSubformControl:="CustomerNavigation.NavigationSubform", _ //The 1st name is the the name of the Main Navigation form that has the Navigation tab and the 2nd name is the main area directly below the tabs where the forms are.
          WhereCondition:="", _
          Page:="", _
          DataMode:=acFormEdit
          
      End Sub

      Comment

      • zu02
        New Member
        • Apr 2014
        • 1

        #4
        Thanks

        Originally posted by mashman
        1) THANK YOU - You are correct this information is a really hard find. I must have read over 500 posts over the last 2 weeks trying to do this. I think they are all talking about the old Tabbed forms more commonly used in pre 2010 access.

        2) GOOGLE SEARCH TIP =>2010 - I found Google was full of lots of pre Access 2010 clutter as it was near impossible to exclude using keywords, but if you use advance search and filter results only in last 2 years, you get a higher amount of results regarding access 2010.

        3) PIC - Yes your example pic is the layout I am working with.

        4) WORKING -

        Code:
        Private Sub cmdSaveNext_Click()
            DoCmd.BrowseTo ObjectType:=acBrowseToForm, _
            ObjectName:="CustomerOrderOverview", _  //This my form attached to Navigation tab I want to move too.
            PathToSubformControl:="CustomerNavigation.NavigationSubform", _ //The 1st name is the the name of the Main Navigation form that has the Navigation tab and the 2nd name is the main area directly below the tabs where the forms are.
            WhereCondition:="", _
            Page:="", _
            DataMode:=acFormEdit
            
        End Sub
        Thank you very much, how you this find - well done!

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          zu02:
          You're Welcome and he found the solution here.
          Post#2 Point#5

          Comment

          Working...