crisis2007
Technical User
I have the following code that I have found and adapted on a form. I am trying to pop-up a message box when the DLookup shows that there is already an employee number and date that exist together in the same record. When the user sees the message, I want the user to choose "yes" if he wants to add this newest record he was inputting or "no" if he wants to cancel this newest record he was inputting. Everything works except when the user chooses yes or no. Both options appear to result in the IsDuplicateRecord to equal True.
Private Function IsDuplicateRecord() As Boolean
On Error Resume Next
Dim PreviousRecordID As Long
Dim xMsg As Long
IsDuplicateRecord = False
PreviousRecordID = 0
PreviousRecordID = DLookup("ExceptionID", "T_Exception", "ExceptionID<>" & ExceptionID & _
" AND EmployeeNumber=" & EmployeeNumber & " AND TDate=#" & [txtDate] & "#")
If PreviousRecordID <> 0 Then
xMsg = MsgBox("This employee already took time that day." & _
vbCrLf & "Do you want to add this entry to the same day?", vbYesNo, "Attention")
If MsgBoxResult.No Then
IsDuplicateRecord = True
ElseIf MsgBoxResult.Yes Then
IsDuplicateRecord = False
End If
End If
End Function
---------------------------------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsDuplicateRecord Then Cancel = 1
End Sub
Any help is certainly appreciated!
Private Function IsDuplicateRecord() As Boolean
On Error Resume Next
Dim PreviousRecordID As Long
Dim xMsg As Long
IsDuplicateRecord = False
PreviousRecordID = 0
PreviousRecordID = DLookup("ExceptionID", "T_Exception", "ExceptionID<>" & ExceptionID & _
" AND EmployeeNumber=" & EmployeeNumber & " AND TDate=#" & [txtDate] & "#")
If PreviousRecordID <> 0 Then
xMsg = MsgBox("This employee already took time that day." & _
vbCrLf & "Do you want to add this entry to the same day?", vbYesNo, "Attention")
If MsgBoxResult.No Then
IsDuplicateRecord = True
ElseIf MsgBoxResult.Yes Then
IsDuplicateRecord = False
End If
End If
End Function
---------------------------------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsDuplicateRecord Then Cancel = 1
End Sub
Any help is certainly appreciated!