crisis2007
Technical User
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.
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.