简体   繁体   English

根据表单中的参数过滤子表单表

[英]Filtering a subform table based on parameters in a form

I have a form with two unbounded comboboxes that work fine (one lists several age values and the other lists several region). 我有一个带有两个无界组合框的表单,它们的工作都很好(一个列出了多个年龄值,另一个列出了多个区域)。 I have a subform, which is a query that refers to the comboboxes, but I can't get it to update when I change values in the comboboxes. 我有一个子窗体,它是一个引用组合框的查询,但是当我更改组合框的值时无法更新它。

My query is: 我的查询是:

Select * from mastertable where (age=[form]![masterform]![age] and region=[form]![masterform]![region] 从mastertable中选择*,其中(age = [form]![masterform]![age] and region = [form]![masterform]![region]

The query works in the sense that if I run it and input the parameters manually it works. 该查询在某种意义上是有效的,如果我运行它并手动输入参数,它将起作用。 It also works in the sense that if I create a button that runs the query on the form, it produces the correct table/query. 从某种意义上说,它还可以工作,如果我创建一个在表单上运行查询的按钮,它将生成正确的表/查询。

My question is how do I get the query to work as a subform? 我的问题是如何使查询作为子表单工作? I'd like to be able to select values in the combo box and see the subform update, rather than having to click on a button that runs the query separately from the form. 我希望能够在组合框中选择值并查看子窗体更新,而不是必须单击与窗体分开运行查询的按钮。

I also tried creating a table that the parameters on the form can bound to, then relating those variables to the mastertable, but that also didn't work. 我还尝试创建一个表格,表格中的参数可以绑定到该表格,然后将这些变量与mastertable关联,但这也行不通。

How do I get a table/query subform to update as information about the parameters changes in the form? 当表格中有关参数的信息发生变化时,如何获取表/查询子表单进行更新? I'm guessing it will require some VBA code on the "after update" event associated with the comboboxes. 我猜想在与组合框关联的“更新后”事件上将需要一些VBA代码。 Any idea how to do this? 任何想法如何做到这一点?

Thanks 谢谢

I figured it out. 我想到了。 I just put a little VBA code that requeries the subtable after update. 我只是放了一些VBA代码,以便在更新后重新查询子表。

Code is [subform].requery 代码是[subform] .requery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM