本文介绍了从另一个表单重新查询一个子表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自己一直在努力解决这个问题,然后在一些帮助下,然后进行搜索;但我没有运气.所以我决定问.

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.

我在 Access 2007 中有两种形式,可以将它们称为MainFormEntryForm.
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.

我已经尝试过此设置代码

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永久与调用它的表单绑定.我认为最好不要将表格绑定到这样的上下文中.我将从保存/关闭"例程中删除重新查询,而是使用acDialog开关以模态方式打开EntryForm:

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复杂化一些东西,该东西可以了解打开它的形式以及需要重新查询的内容.我认为最好将这种内容保持在与使用它的上下文接近的位置,并使被调用表单的代码尽可能简单.

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.

这里的一个原则可能是,每当您使用另一个表单中的Forms集合重新查询表单时,这都很好地表明了您的体系结构不正确-在我看来,这种情况很少发生.

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.

这篇关于从另一个表单重新查询一个子表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 02:23