我有一个带有子表单的绑定(bind)表单。当我对主窗体进行更改然后单击子窗体时,出现以下错误:
The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing {program name} from saving the data in the field.
- If this is a macro, open the macro in the Macro window and remove the action that forces a save (for example, GoToControl).
- If the macro includes a SetValue action, set the macro to the AfterUpdate property of the control instead.
- If this is a function, redefine the function in the Module window.
如果我在主窗体上做了修改,然后点击记录选择框或者按Shift+Enter保存,然后点击我做的子窗体没有收到错误消息。
最佳答案
事实证明,罪魁祸首是在 Form_BeforeUpdate
过程中对 DoEvents
的调用。最简单的解决方案是删除对 DoEvents
的调用。
在我的特殊情况下,对 DoEvents
的调用深埋在调用堆栈中,因此请务必遵循所有代码路径或只对 DoEvents< 进行全局搜索
.
要重现此错误:
- 创建一个新表单
- 为表单指定 RecordSource(即,使其成为绑定(bind)表单)
- 添加子窗体控件(注意:子窗体控件不需要指定SourceObject)
- 将 Form BeforeUpdate 属性设置为
[Event Procedure]
将以下代码添加到表单的代码模块中:
Private Sub Form_BeforeUpdate(Cancel As Integer) DoEvents End Sub
- 更改主窗体上的数据
- 直接点击子窗体控件
- 收到问题中指出的错误消息
关于ms-access - 错误 2115 : Macro/function set to BeforeUpdate/ValidationRule is preventing {pgm} from saving data in the field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25367080/