Prevent duplicate from 3 text

  • Thread starter ashraf_al_ani via AccessMonster.com
  • Start date
A

ashraf_al_ani via AccessMonster.com

Dear All
I have a form contais 3 text
name, father_name,Sur_name

how can i prevent the duplicate if a user entered

John smith george


and in another record he enterd the same name

John smith george

i want to display a msgbox to tell him that the name is duplicated

best wishes
 
J

John W. Vinson

Dear All
I have a form contais 3 text
name, father_name,Sur_name

how can i prevent the duplicate if a user entered

John smith george

Why should you prevent such an entry?

My name is John Vinson. (John Wilmot)
My father's name was John Vinson. (John Walker Jr.)
His father's name was John Vinson. (John Walker Sr.)

Names are not unique; duplicate names are *perfectly legitimate* entries and
your program should not prohibit them. I once worked with Dr. Lawrence David
Wise and his colleague, Dr. Lawrence David Wise.
and in another record he enterd the same name

John smith george

i want to display a msgbox to tell him that the name is duplicated

If you want just a warning (not a prevention) you can use the form's
BeforeUpdate event with code like:

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
If Not IsNull(DLookUp("somefield", "yourtable", _
"[Name] = """ & Me![Name] & """ AND Father_Name = """ _
& Me![Father_Name] & """ AND Sur_Name = """ _
& Me![Sur_Name] & """") Then
iAns = MsgBox("This name already exists; add it anyway?", vbYesNo)
If iAns = vbNo Then
Cancel = True ' cancel the addition to the table
Me.Undo ' erase the user's input
End If
End If
End Sub
 
A

ashraf_al_ani via AccessMonster.com

John said:
Dear All
I have a form contais 3 text
[quoted text clipped - 3 lines]
John smith george

Why should you prevent such an entry?

My name is John Vinson. (John Wilmot)
My father's name was John Vinson. (John Walker Jr.)
His father's name was John Vinson. (John Walker Sr.)

Names are not unique; duplicate names are *perfectly legitimate* entries and
your program should not prohibit them. I once worked with Dr. Lawrence David
Wise and his colleague, Dr. Lawrence David Wise.
and in another record he enterd the same name

John smith george

i want to display a msgbox to tell him that the name is duplicated

If you want just a warning (not a prevention) you can use the form's
BeforeUpdate event with code like:

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
If Not IsNull(DLookUp("somefield", "yourtable", _
"[Name] = """ & Me![Name] & """ AND Father_Name = """ _
& Me![Father_Name] & """ AND Sur_Name = """ _
& Me![Sur_Name] & """") Then
iAns = MsgBox("This name already exists; add it anyway?", vbYesNo)
If iAns = vbNo Then
Cancel = True ' cancel the addition to the table
Me.Undo ' erase the user's input
End If
End If
End Sub
thank you

you solved my problem

best regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top