我有一個運行宏的按鈕,該宏呼叫函式“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
uj5u.com熱心網友回復:
我解決了我的問題。
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478488.html
上一篇:VBA和Python之間的IPC
