使用子表单中字段的总和填充字段 [英] populating a field using the sum of a field from a subform
问题描述
嗨 - 我有一个名为mainForm的表单,它有一个名为subForm的子表单。子表单有一个名为subCost的数字字段。每个mainForm记录都有许多subForm记录。在主窗体上,有一个名为mainCost的字段。
每当有人对subCost字段进行更改时,我想用subCost值的总和填充mainCost字段。 mainForm和subForm由mainID = subID连接。
这是我自己写的这个蹩脚的尝试(在subCost字段的After Update事件上)。
Hi - I have a form called mainForm that has a subform called subForm. The subform has a numeric field called subCost. There are many subForm records for every mainForm record. On the main form, there is a field called mainCost.
Whenever someone makes a change to the subCost field, I want to populate the mainCost field with the sum of the subCost values. The mainForm and the subForm are joined by mainID = subID.
Here is my lame attempt at writing this myself (on the After Update event of the subCost field).
推荐答案
你走在正确的轨道上,试着在设计视图中设置MainCost的控制源。 />
You are on the right track, try just setting the control source of the MainCost in design view.
谢谢。我不认为我可以这样做,因为用户仍然需要能够编辑mainCost字段。有时候甚至不会在subForm上记录,而mainCost也必须更新。此外,它的记录源需要保持与基础表绑定,因为我想在那里存储数据。
Hi and thanks. I don''t think I can do it this way since the user needs to still be able to edit the mainCost field. Sometimes there won''t even be a record on the subForm and the mainCost will have to be updated. Also it''s record source needs to remain tied to an underlying table as I want to store data there.
您可以根据需要在VBA代码中更改控制源。
-AJ
You can change the control source on a need by need basis in the VBA code.
-AJ
这篇关于使用子表单中字段的总和填充字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!