过滤器访问组合框
我有一个访问数据库,其表单包含两个组合框。一个组合框根据第一个组合框的选择来过滤其选项。这工作得很好,但是 - 我有一个命令按钮可以更改表单的记录源。不过,我只知道如何根据一张表填充组合框。因此,当表单更改记录源时,组合框仍然填充第一个记录源中的选项。如何创建一个查询来填充组合框选项,而不是一般在一个表上,而是基于当时表单的记录源?
I have an access database with a form that contains two combo boxes. One combo box filters its options based on the selection of the first combo box. This works perfectly but - I have a command button that changes the record source of the form. I only know how to populate the combo boxes based on one table though. So when the form changes record sources the combo boxes are still filled with options from the first record source. How can I create a query that populates the combo box options not on one table in general but based on whatever the record source of the form is at the time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在更改 RecordSource 的同一命令按钮处理程序中,为每个组合框分配一个新的 RowSource。更好的是,在由按钮处理程序调用的单独子程序中执行此操作。您的代码必须知道或能够弄清楚新的 RowSource 应该是什么才能与新的 RecordSource 相对应。
编辑回复评论
RowSource 不必是 QueryDef 对象,它可以只是 SQL 语句:
我在编辑的同时看不到评论,但我不明白你在第二次问什么....在第二次,单独看看评论,我认为你在问它,你可以将 RowSource 设置为表单的 RecordSource 属性。在我看来,这是一个坏主意——RecordSource 中的列可能比您想要在 RowSource 中处理的列多得多,并且查询构造的基本原则是仅请求您想要的列。
In the same command button handler that changes the RecordSource, assign a new RowSource to each combo box. Better yet, do this in a separate sub that's called by the button handler. Your code will have to know, or be able to figure out, what the new RowSource should be to correspond to the new RecordSource.
Edit in reply to comments
The RowSource doesn't have to be a QueryDef object, it can just be an SQL statement:
I can't see the comments at the same time I'm editing, but I didn't understand what you were asking in the second.... On a second, separate, look at the comments, I think you're asking it you can set the RowSource to the form's RecordSource property. This strikes me as a bad idea--you've probably got many more columns in the RecordSource than you'll want to deal with in the RowSource, and a basic principle of query construction is to only request the columns you want.