On a BeforeUpdate event, I've got two bits of code. One calls an Audit function and one checks to see if some criteria are met for data validation.
What I'd like to do is have them work together so that if the data validation criteria is not met, it does not call the audit functions and the values won't be saved.
I'm trying to avoid undoing all the changes on the form that have been made, as I'd like to keep them but notify the user that they need to change one piece in particular.
Currently, the popup message works, and the form does not save but two undesirable things happen:
1) The audit code still fires
2) I get a 'no current record' error as well
The code I am using is:
What I'd like to do is have them work together so that if the data validation criteria is not met, it does not call the audit functions and the values won't be saved.
I'm trying to avoid undoing all the changes on the form that have been made, as I'd like to keep them but notify the user that they need to change one piece in particular.
Currently, the popup message works, and the form does not save but two undesirable things happen:
1) The audit code still fires
2) I get a 'no current record' error as well
The code I am using is:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "Reason", "Status='" & Me.Status & "' AND Reason='" & Me.Reason & "'") = 0 Then
MsgBox "That Reason and Status code combination is not valid", vbInformation, "Mismatch"
Cancel = True
Else
Call TrackChanges(Me)
Form_BeforeUpdate_Exit:
Exit Sub
End If
End Sub