【问题标题】:BeforeUpdate issue - Runtime (error 2115)更新前问题 - 运行时(错误 2115)
【发布时间】:2020-07-11 17:58:34
【问题描述】:

我写了以下查询:

Private Sub Size_Sqft_BeforeUpdate(Cancel As Integer)
  Me!Size_Sqft = Nz(Me!Size_Sqft, 0)
End Sub

但是在删除字段中的零使其为空时,我收到以下错误:

运行时错误 2115

此字段的更新和验证规则属性设置为之前的宏和函数会阻止公司的手动数据输入屏幕保存字段中的数据。

【问题讨论】:

    标签: vba ms-access


    【解决方案1】:

    您必须将该代码放入该字段的 AfterUpdate 事件中。

    【讨论】:

      【解决方案2】:

      我知道这是一个旧线程,并且已经得到回答,但是还有另一个解决方案不需要多次写回您的数据库。我添加它以防其他人遇到这个问题。

      Private Sub ControlName_BeforeUpdate(Cancel as integer)
          If isValid(Me.ControlName.Value) = False Then
              Cancel = True
              Me.ControlName.Undo
          End If
      End Sub
      
      Private Function isValid(ByVal...) as boolean
          ' validate control value here
      End Function
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-14
        • 1970-01-01
        • 2010-10-15
        • 2017-07-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多