【发布时间】:2019-01-30 23:27:29
【问题描述】:
所以我有一个表格可以更新 Microsoft Access 中的表格。如果未填写“名字”,我正在使用更新前事件调用来阻止表单更新。
我基本上只希望在填写完所有内容后保存表格,然后切换查看更新的表格(如果未取消下的位)。
当前弹出框说“您必须输入名字”正确触发,下一个弹出框询问用户是否要撤消任何更改触发。但随后会出现一个弹出框,显示“无当前记录”,然后视图更改为表格。我不确定为什么会发生这一切。
Option Compare Database
Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = False
' perform data validation
If IsNull(Me.customer_f_name) Then
MsgBox "You must enter a First Name.", vbCritical, "Data entry error..."
Me.customer_f_name.BorderColor = vbRed
DoCmd.GoToControl "customer_f_name"
Cancel = True
End If
If Not Cancel Then
DoCmd.SelectObject acTable, "ticket_tracker_table"
DoCmd.Requery
DoCmd.GoToRecord acDataTable, "ticket_tracker_table", acLast
End If
' if the save has been canceled or did not pass the validation , then ask to Undo changes
If Cancel Then
If MsgBox("Do you want to undo any changes?", vbYesNo, "Confirm") = vbYes Then
Me.Undo
End If
End If
End Sub
【问题讨论】:
-
哪个语句导致您不喜欢该消息?尚不清楚是否回答了先前的问题。您应该能够在语句 Cancel = False 上设置调试,然后逐步执行,直到找到更多信息。
-
我现在不是windows pc,但我认为您的错误是您在保存之前尝试访问新记录,即此代码仍在@987654322 中运行@时间
-
为什么表是打开的?你是这个数据库的唯一用户吗?