vba 从父表单过滤子表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11021143/
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-11 16:29:14  来源:igfitidea点击:

Filter Subform from Parent Form

ms-accessvbaaccess-vbams-access-2003

提问by Ish

I have a subform inside a parent form. The subform shows up as a datasheet inside the parent form. I have two comboboxes in the parent form. When the user chooses a value from the combobox the subform should get filtered according to those two values.

我在父表单中有一个子表单。子窗体在父窗体中显示为数据表。我在父表单中有两个组合框。当用户从组合框中选择一个值时,子表单应根据这两个值进行过滤。

The following is the code I used. It opens up another window and shows the filtered values instead of showing it within the parent subform.

以下是我使用的代码。它打开另一个窗口并显示过滤后的值,而不是在父子窗体中显示它。

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "3_Properties"

stLinkCriteria = "[Program_Name]=" & "'" & Me![Combo2] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Thanks

谢谢

采纳答案by Fionnuala

You can take advantage of link child and master fields to filter the subform without using any code. You can set the link master fields for your subform to the name of the combobox controls and the child fields to the relevant related columns (fields). Separate each entry with a semi-colon.

您可以利用链接子字段和主字段来过滤子表单,而无需使用任何代码。您可以将子表单的链接主字段设置为组合框控件的名称,将子字段设置为相关的相关列(字段)。用分号分隔每个条目。

You can also set the record source of the subform at run time.

您还可以在运行时设置子窗体的记录源。

 sSQL = "SELECT BText FROM Table WHERE AText = '" & Me.MyCombo & "'"
 Me.MySubformControlName.Form.Recordsource = sSQL