如果用户在 MS ACCESS 表单中的记录插入失败,则创建弹出窗口

Create popup if record insertion fails for user in MS ACCESS Form

我有一个按钮可以运行调用函数“CheckRecordCount()”的宏,然后调用 Sub Command1_Click。

如果表单没有进入新的空白记录(换句话说,没有插入新记录),我想要一个弹出窗口。

我尝试了一个错误函数,但错误似乎无论如何都会执行。

Public Function CheckRecordCount()
    Call Command1_Click
End Function

Private Sub Command1_Click()

    On Error GoTo FailedInsertion
   DoCmd.GoToRecord , , acNewRec
   
FailedInsertion:

MsgBox "Fill out all fields and try again. Record insertion failed."

End Sub

我解决了我的问题。

Public Function CheckRecordCount()
    Call Command1_Click

End Function

Private Sub Command1_Click()

   Dim varTotalBefore As Integer
   Dim varTotalAfter As Integer
   varTotalBefore = Forms![your form title].Form.Recordset.RecordCount
   On Error Resume Next
   DoCmd.GoToRecord , , acNewRec
   On Error GoTo 0
   varTotalAfter = Forms![your form title].Form.Recordset.RecordCount
   
If varTotalAfter = varTotalBefore Then
MsgBox "Request submission failed. Ensure all fields are filled out and try again."
End If

If varTotalAfter > varTotalBefore Then
MsgBox "Request successfully submitted!"
End If

End Sub