Navigating to a different tab in navigation subfor

2019-01-25 23:31发布

问题:

In an ms access 2010 database, I have a listbox whose afterupdate procedure needs (among other things) to navigate to a specific tab in a navigation subform. I can get it to change the SourceObject property of the navigation subform, but the selected tab does not get changed, so the user ends up seeing the right source object with the wrong tab selected. This looks unprofessional. How can I change both the selected tab and the source object?

I uploaded a simplified database that recreates the problem to this file sharing site.

The list box that needs its afterupdate method changed is called lstbxClients. Here is my current draft of its afterupdate method, which is currently throwing an error:

Private Sub lstbxClients_AfterUpdate()
  Dim rst
  Set rst = Me.RecordsetClone
  rst.FindFirst "ClientNumber = " & lstbxClients.Column(0)
  Me.Bookmark = rst.Bookmark
  'Forms!Main!NavigationSubform.Form!NavigationSubform.SourceObject = "qryListCommunicationForms"
  DoCmd.BrowseTo acBrowseToForm, "qryListCommunicationForms", "Forms!Main!NavigationSubform.Form!NavigationSubform"
  Form.NavigationSubform "  "
  'Forms!Main!NavigationSubform.Form!NavigationSubform.SelectedTab = "CommFormsNavBtn"
  Set rst = Nothing
End Sub  

How do I change the code above so that it changes both the selected tab AND the source object of the navigation subform when the user clicks on a different record in the listbox?

回答1:

Access gave a relatively decent explanation of what the proper syntax of the path is.

So your BrowseTo command should look like this:

DoCmd.BrowseTo acBrowseToForm, "qryListCommunicationForms", "Main.NavigationSubform>FindClientsNavigation.NavigationSubform"



回答2:

Use the syntax below

DoCmd.BrowseTo acBrowseToForm, "qryListCommunicationForms", "Main.NavigationSubform>findClientsNavigation.NavigationSubform", "ClientNumber = " & lstbxClients.Column(0)

and

DoCmd.BrowseTo acBrowseToForm, "ListAddresses", "Main.NavigationSubform>findClientsNavigation.NavigationSubform", "ClientNumber = " & lstbxClients.Column(0)

The only change is the second parameter syntax , use

"Main.NavigationSubform>findClientsNavigation.NavigationSubform"

Hope this helps



回答3:

The easiest way to do it :

Form_NavFormName.NavigationSubform.SourceObject = "FormName"