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!

Prevent duplicating values for First Name, Middle Name and Last Name

Status
Not open for further replies.

xyzlook

Technical User
Oct 1, 2005
27
US
My Table “Cast” has these fields:

cID (PK), cFName, cMName and cLName

The form I am using to update this table is called fCast.

I would like to prevent entering same name twice. I have used the following code to prevent entering same Title twice which is working. But I am not sure how to concatenate 3 name fields and apply similar codes. Can someone please help?

My code to prevent duplicating a title

Private Sub iTitle_AfterUpdate()



Dim iTitle As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

iTitle = Me.iTitle.Value
stLinkCriteria = "[iTitle]=" & "'" & Replace(Me![iTitle], "'", "''") & "'"




'Check Items table for duplicate iTitle
If DCount("iTitle", "Items", _
stLinkCriteria) > 0 Then


'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Item Title " _
& iTitle & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.", _
vbInformation, "Duplicate Information"
'Go to record of original Title
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If

Set rsc = Nothing

End Sub

 
How are ya xyzlook . . .

Something like the folowing in the forms [blue]Before Update[/blue] event is typical ...
Code:
[blue]   Dim Cri As String
   
   [purple][b]Cri[/b][/purple] = "[cFName] = '" & Me!cFName & "' AND " & _
         "[cMName] = '" & Me!cMName & "' AND " & _
         "[cLName] = '" & Me!cLName & "'"
   
   If DCount("[cID]", "Cast", [purple][b]Cri[/b][/purple]) > 0 Then
      MsgBox "Duplicate FullName!"
      Cancel = True
   End If[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1:

Thanks for taking the time to help me.

I added the suggesed code to the Before Update event of my form called sfCast but it allowed me to enter a duplicate name. What am I doing wrong?


Here is the entire code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Cri As String

Cri = "[cFName] = '" & Me!cFName & "' AND " & _
"[cMName] = '" & Me!cMName & "' AND " & _
"[cLName] = '" & Me!cLName & "'"

If DCount("[cID]", "Cast", Cri) > 0 Then
MsgBox "Duplicate Name!"
Cancel = True
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top