I have used the code below to try and bring up a message box when I enter a duplicate number in the 'TFN' field but it stops me at the 'If' line.
Code:
Private Sub TFN_AfterUpdate()
Dim NewTFN As String
Dim stLinkCriteria As String
NewTFN = Me.TFN.Value
stLinkCriteria = "[TFN] = " & "'" & NewTFN & "'"
If Me.TFN = DLookup("[TFN]", "tbl_SAlert", stLinkCriteria) Then
MsgBox "This TFN " & NewTFN & ", has already been entered in the database." _
& vbCr & vbCr & "Please check TFN again.", vbInformation, "Duplicate TFN entered"
Me.Undo
End If
End Sub
The table used with the form is titled "tbl_SAlert" and the field on the form is entitled "TFN".
Could someone please advise where I am going wrong?