vba - 重新计算父表单,而不会从子表单的当前记录中失去焦点
问题描述
在访问数据库中,我有一个带有表格子表单的主表单。我希望在更改子窗体的任何记录的任何值时重新计算主窗体的每个控件。我尝试将(me.parent.recalc)之类的东西应用于每个子表单的控件,但发现现在当我更改子表单的“任何”记录时,焦点将偏移到子表单第一条记录的同一字段。有什么解决办法吗?问候
解决方案
假设您在主窗体上的子窗体控件名为ctlSubForm
,这将是您在子窗体中调用的代码示例,例如在AfterUpdate
事件过程中:
'Store the current sub forms record/bookmark
Dim currentRecord As Variant
currentRecord = Me.Bookmark
'Requery the main form, causing the first record of subform will be selected
'(instead place your existing code here)
Me.Parent.Requery
'Set the sub forms record/bookmark to the stored record/bookmark
Me.Bookmark = currentRecord
'Set the focus to the main forms sub form control
'(this is necessary to really get the focus back to the subform)
Me.Parent.ctlSubForm.SetFocus
推荐阅读
- python - Python 正则表达式:如何实现一个正则表达式来检查匹配的括号集?
- node.js - 在 Joi (Node.js) 中使用外部函数进行验证
- python - Python - 方法参数中的值解包顺序
- python - 如何将用户输入数据写入外部文本文件?
- angular - 如何根据可观察对象设置角度垫按钮属性?
- javascript - 背景颜色不适用于 for 循环
- python - 从装饰器访问 Kedro 上下文
- docker - 如何从 mapr 卷中读取多个文件(pdf)执行 OCR 并使用 kubernetes 作业在 mapr 卷中转储
- javascript - 反应表单将标题传递给 api
- vb.net - 删除尾随文本(多个字符)