I am trying to edit some code to prevent duplicate entries in a database based on two fields instead of just one. I would like to check the Fuel Usage table for records that match both the invoice number and date purchased. Any ideas on how to add the date purchased as criteria for duplicates in this code? Thank you!
My existing code looks like this:
My existing code looks like this:
Code:
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
SID = Me.Invoice_No.Value
stLinkCriteria = "[Invoice No]=" & "'" & SID & "'"
'Check Fuel Usage table for duplicate invoice numbers
If DCount("Invoice_No", "tbl_FuelUsage", _
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Invoice Number " _
& SID & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.", _
vbInformation, "Duplicate Information"
'Go to record of original Invoice Number
rsc.FindLast stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If
Set rsc = Nothing
End Sub