ms-access - 错误 2115 : Macro/function set to BeforeUpdate/ValidationRule is preventing {pgm} from saving data in the field

标签 ms-access vba

我有一个带有子表单的绑定(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< 进行全局搜索.


要重现此错误:

  1. 创建一个新表单
  2. 为表单指定 RecordSource(即,使其成为绑定(bind)表单)
  3. 添加子窗体控件(注意:子窗体控件不需要指定SourceObject)
  4. 将 Form BeforeUpdate 属性设置为 [Event Procedure]
  5. 将以下代码添加到表单的代码模块中:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
        DoEvents
    End Sub
    
  6. 更改主窗体上的数据
  7. 直接点击子窗体控件
  8. 收到问题中指出的错误消息

关于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/

相关文章:

vba - 使用 VBA 获取 word 中的所有交叉引用

从 MS Access 导入 Python : "Invalid connection string attribute"

xml - 将多个 Access 表导出到单个 XML

sql - 更新语句 Sql Access 双内连接

excel - 如何将 Power Query 表保存为新工作簿中的常规表(无连接)?

excel - 我如何改进我的功能来处理 Application.FileSearch VBA 的替代方案

vba - VBA 用户窗体 TreeView 中是否存在键

ms-access - 如何在 Access SQL 中执行 INTERSECT 查询

c# - access 2007 是否可以与 30 个用户并行工作?

excel - 用excel处理变量