Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate Entry Message

Status
Not open for further replies.

crisis2007

Technical User
Apr 2, 2007
114
US
I have fields named TDate and EmployeeNumber in a table named T_Exception. When I enter data in a form tied to the table, I wish for there to be a message box that pops up and warns that there is already a record that has both the same employee number and the same date together. I tried the following code I found and it does not work for me unless I remove the part referencing TDate and it seems to work ok on the employee number alone. I have spent quite some time on this and seem to be going nowhere on it. Any help would sure be appreciated!

Private Function IsDuplicateRecord() As Boolean
On Error Resume Next
Dim PreviousRecordID As Long


IsDuplicateRecord = False
PreviousRecordID = 0
PreviousRecordID = DLookup("ExceptionID", "T_Exception", "ExceptionID<>" & ExceptionID & _
" AND TDate=" & TDate) & " AND EmployeeNumber=" EmployeeNumber

If PreviousRecordID <> 0 Then
MsgBox "Customer Exists Already"
IsDuplicateRecord = True
End If

End Function
----------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsDuplicateRecord Then Cancel = 1
End Sub

I am somewhat new to code and still learning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top