【问题标题】:Access DB VBA 'No current record error' using Form_BeforeUpdate(Cancel As Integer)使用 Form_BeforeUpdate(取消为整数)访问 DB VBA“无当前记录错误”
【发布时间】:2023-04-05 11:01:01
【问题描述】:

您好,我在 Access 中更新之前有以下表单代码,但它抛出错误“没有当前记录错误”。任何帮助,将不胜感激。作业检查是组合框,评论是长文本框。除此错误外,代码运行良好。

Private Sub Form_BeforeUpdate(Cancel As Integer)
If ([Job Checks] = "Moderate" And Nz([Comments]) = "") Then
MsgBox "You need to fill out Comments"
Comments.SetFocus
Cancel=True
End If 
End Sub

【问题讨论】:

  • 在哪一行出现错误? “工作正常”是什么意思?
  • 如果在 Job Checks 为“中等”时 cmets 为空,它不会让我保存记录并触发 MsgBox 错误,然后触发第二个错误“No current record.”。当我填写 cmets 框时,它将毫无问题地保存记录。
  • 那么如何保存记录呢?错误发生在哪一行?
  • 命令按钮点击事件 'DoCmd.GoToRecord , , acNewRec' Me.Dirty = False
  • 谢谢,我认为问题出在我的保存和清除按钮上,而不是更新前的表格 'Private Sub Command32_Click()' 'On Error Resume Next' 'Me.Dirty = False' 'If Err.Number = 0 Then' 'DoCmd.GoToRecord , , acNewRec' 'Else: MsgBox Err.Description, vbCritical, "Error"' 'End If' 'End Sub'

标签: vba ms-access


【解决方案1】:

尝试使用控件而不是字段:

Private Sub Form_BeforeUpdate(Cancel As Integer)

    If Me![Job Checks].Value = "Moderate" And Nz(Me!Comments.Value) = "" Then
        MsgBox "You need to fill out Comments."
        Me!Comments.SetFocus
        Cancel = True
    End If 

End Sub

【讨论】:

  • 试过这个仍然是同样的问题,首先填充 MsgBox“你需要填写评论”,然后是第二个错误“没有当前记录。”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多