View Single Post
  #3  
Old May 22nd, 2008, 06:23 PM posted to microsoft.public.access.forms
Ryan Tisserand
external usenet poster
 
Posts: 22
Default Check For Existing Record

Here is my solution for multiple field duplication. I first join the two
fields in a query. For your example I would do this in a query.
NoDuplicates:[InspDate]&""&[StoreNo]
Now that you have one field named NoDuplicates to deal with, in the "Before
Update" event of InspDate you would use this code

If not IsNull(DLookup("[NoDuplicates]", (YourQueryName), "[NoDuplicates]=" &
Forms(YourFormName)![InspDate])) Then
MsgBox "Store and Inspection Date already exist. Please correct",
vbCritical, "Duplicate Entry"
End If
Exit Sub

Dont know if this will help but this works for me.


"ridgerunner" wrote:

I have a unique index set on two fields in my table, InspDate and StoreNo. I
am trying to trap the error of attempting to add a duplicate by having the
code below in the LostFocus Event for the InspDate. I am running around in
circles. Can someone please help?


Private Sub InspDate_LostFocus()
If DMInspections.StoreNo = True Then
ElseIf DMInspDet.InspDate = True Then
MsgBox "Store and Inspection Date already exist. Please correct"
Me.InspDate.SetFocus
Else: Me.DMnameID.SetFocus
Exit Sub
End If
End Sub


tia
ridgerunner