If/Else code not working right

deadtrees

New member
Local time
Today, 10:22
Joined
Apr 20, 2009
Messages
4
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:

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
 
The easiest way to debug these type of errors is to add a bookmark to the code. When it breaks during execution, walk through it a line at a time and see where the logic takes you, and what exactly is in the variables. The immediate window is useful for evaluating logical expressions and Domain Aggregate functions that don't reveal their contents by hovering over them with the cursor.
 

Users who are viewing this thread

Back
Top Bottom