vba 导航到导航子表单中的不同选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20366387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:47:43  来源:igfitidea点击:

Navigating to a different tab in navigation subform

vbams-accessaccess-vbams-access-2010

提问by CodeMed

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?

在 ms access 2010 数据库中,我有一个列表框,其 afterupdate 过程需要(除其他外)导航到导航子表单中的特定选项卡。我可以让它更改导航子表单的 SourceObject 属性,但选定的选项卡不会更改,因此用户最终会看到选择了错误选项卡的正确源对象。这看起来不专业。如何更改所选选项卡和源对象?

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:

需要更改 afterupdate 方法的列表框被调用lstbxClients。这是我当前对其 afterupdate 方法的草稿,该方法目前正在引发错误:

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?

如何更改上面的代码,以便在用户单击列表框中的不同记录时更改所选选项卡和导航子表单的源对象?

采纳答案by Bobort

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

Access 对路径的正确语法给出了相对体面的解释。

Path argument is of the form: MainForm1.Subform1>Form1.Subform1

路径参数的形式为: MainForm1.Subform1>Form1.Subform1

So your BrowseTo command should look like this:

所以你的 BrowseTo 命令应该是这样的:

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

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

回答by evenprime

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"

"Main.NavigationSubform>findClientsNavigation.NavigationSubform"

Hope this helps

希望这可以帮助

回答by Tony

The easiest way to do it :

最简单的方法:

Form_NavFormName.NavigationSubform.SourceObject = "FormName"