I have a button that runs a macro that calls function "CheckRecordCount()" which then calls Sub Command1_Click.
I want a pop up if the form does not proceed to a new blank record (in other words a new record is not inserted).
I tried an error function but the error seems to execute regardless.
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
CodePudding user response:
I solved my problem.
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