在VBA中设置Subform RecordSource [英] Setting Subform RecordSource in VBA

查看:94
本文介绍了在VBA中设置Subform RecordSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


我正在尝试利用VBA在命令按钮点击上设置子表单的记录源。我的表单用于按查询搜索并在子表单中显示结果。如果我在属性表中设置子表单源它可以正常工作,但在打开表单时加载完整的查询。我希望子窗体变为空白,直到我单击搜索按钮。这是我的按钮的代码:

Greetings,

I''m trying to utilize VBA to set a subform''s recordsource on a command button click. My form is used to search by a query and display the results in the subform. If I set the subform source in the property sheet it works properly but loads the full query on opening the form. I want the subform to be blank until I click the search button. Here is my button''s code:

展开 | 选择 | Wrap | 行号

推荐答案

你需要Requery SubForm控件本身,而不是作为其记录源的实际Form。尝试:
You need to Requery the SubForm Control itself, and not the actual Form that is its Record Source. Try:
展开 | 选择 | Wrap | 行号


ADezii的响应非常接近完美。它处理您引用的错误消息以及解释它应该起作用的原因。

您的问题有两个方面。另一种是在按钮单击实际指定之前避免记录集加载。这比看起来容易。只需设计(保存)没有 RecordSource 值的表单。


我怀疑,通过更明智地使用现有表单属性和调用参数,你可以不采用这种繁琐的方法就可以做到这一点。例如,过滤器属性可以作为其打开调用的一部分传递给表单。我会把这个想法留给你。这可能会产生一个单独的问题。
ADezii''s response is (pretty close to) perfect. It handles the error message you quote as well as explaining why it should work.

Your question has two aspects though. The other is avoiding the recordset loading until actually specified by the Button click. This is easier than it might appear. Simply design (Save) the form with no RecordSource value.

I suspect though, that with more judicious use of existing form properties and calling parameters, you could do this without resorting to such a cumbersome approach. Filter properties can be passed to a form as part of its open call, for instance. I''ll leave that thought with you. It might result in a separate question.


@ADezii


谢谢。这样就解决了。知道什么时候是控件以及什么时候需要重新获得这种形式?我刚刚开始使用VBA和Access。非常感谢您的时间和帮助。
@ADezii
Thank you. This worked out. Is there a trick to knowing when it is the control and when it is the form that needs to be requeried? I''ve just delved into utilizing VBA and Access. Your time and assistance is most appreciated.


这篇关于在VBA中设置Subform RecordSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆