I have a Single form where I am trying to get a message box to prompt the user when 2 fields from my form match what is in the table and other one doesn't match.
This is the code I have which is in a button on click event.
If Not IsNull(Me.L_dt) Then
If Me.Ref = DLookup("[Ref]", "tbl", "[Ref]='" & Forms!MyForm!Ref & "'") And _
Me.Class = Nz(DLookup("[ClassTy]", "tbl", "[ClassTy]<>'" & Forms!MyForm!ClassTy & "'"), 0) And _
Me.L_dt = DLookup("L_dt", "tbl", "L_dt= #" & Format(Forms!MyForm![L_dt], "yyyy\/mm\/dd") & "#") Then
If MsgBox("This record has an existing Learn Dt for this Ref", vbOKCancel) = vbCancel Then
Cancel = True
Me.Undo
Exit Sub
End If
End If
End If
Expected Result should be if the Ref and L_Dt are the same but the Class is different then prompt user, if L_Dt, Ref and Class are all the same this is fine.
Currently this is not working as expected as getting prompt when all 3 match.
I think it's me.ClassTy line that is wrong but when I change the <> to = it still does not work.