如何重新查询从另一种形式的子窗体? [英] How to requery a subform from another form?
问题描述
我对我自己的这个问题苦苦挣扎,然后用一些帮助,然后搜索一下吧;但我没有任何运气。所以,我决定问。
I've struggling with this problem on my own, then with some help, then search about it; but I haven't had any luck. So I decided to ask.
我在两种形式的访问2007 的可以给他们打电话的MainForm
和 EntryForm
。
的MainForm
有一个子窗体和一个按钮。该按钮可打开 EntryForm
在添加模式。我想要做的是,当 EntryForm
保存新的记录将更新(重新查询)的的MainForm
子窗体。
I have two forms in Access 2007 lets call them MainForm
and EntryForm
.
MainForm
has a subform and a button. The button opens the EntryForm
in Add Mode. What I want to do is when the EntryForm
saves the new record it would update (requery) the subform in MainForm
.
我已经尝试此设置code
I've try this setup code
Private Sub cmdSaveAndClose_Click()
DoCmd.Save
'requery list
Forms![MainForm]![subformName].Requery
'' I've also tried these
'Forms![MainForm]![subformName].Form.Requery
'Forms.("MainForm").[subformName].Requery
'Forms.("MainForm").[subformName].Form.Requery
DoCmd.Close
End Sub
没有这些尝试中似乎工作。有没有一种方法,使这项重新查询? 感谢您提前帮助。
None of these attempts seem to work. Is there a way to make this requery? Thanks for the help in advance.
推荐答案
在解决这个问题的方法只是一个注释:
Just a comment on the method of accomplishing this:
你把你的EntryForm永久绑定到你从调用它的形式。我认为这是最好不要有依赖于上下文这样的形式。我从保存/关闭程序删除重新查询,而是有模式打开EntryForm,使用acDialog开关:
You're making your EntryForm permanently tied to the form you're calling it from. I think it's better to not have forms tied to context like that. I'd remove the requery from the Save/Close routine and instead open the EntryForm modally, using the acDialog switch:
DoCmd.OpenForm "EntryForm", , ,"[ID]=" & Me!SubForm.Form!ID, , acDialog
Me!SubForm.Form.Requery
这样一来,EntryForm没有牵制在一个范围内使用。另一种方法是复杂EntryForm的东西,是有见地,其中形式打开了它,哪些需要重新查询。我认为这是更好地保持那种接近在它的使用范围内的事情,并保持一个名为form的code尽可能的简单。
That way, EntryForm is not tied down to use in one context. The alternative is to complicate EntryForm with something that is knowledgable of which form opened it and what needs to requeried. I think it's better to keep that kind of thing as close to the context in which it's used, and keep the called form's code as simple as possible.
也许,这里的原则是,你正在重新查询使用窗体收集从另一种形式的窗体中的任何时候,这是一个很好的迹象不对了你的架构 - 这应该很少发生,在我看来
Perhaps a principle here is that any time you are requerying a form using the Forms collection from another form, it's a good indication something's not right about your architecture -- that should happen seldom, in my opinion.
这篇关于如何重新查询从另一种形式的子窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!