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!

Yes/No MessageBox Problem with DLookup

Status
Not open for further replies.

crisis2007

Technical User
Apr 2, 2007
114
US
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!
 
Thank You! You solved my problem that I spent a couple of hours trying to fix with no luck. I appreciate your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top