A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Prevent duplicate from 3 text



 
 
Thread Tools Display Modes
  #1  
Old April 8th, 2010, 06:33 AM posted to microsoft.public.access.forms
ashraf_al_ani via AccessMonster.com
external usenet poster
 
Posts: 14
Default Prevent duplicate from 3 text

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

--
Message posted via http://www.accessmonster.com

  #2  
Old April 8th, 2010, 07:14 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Prevent duplicate from 3 text

On Thu, 08 Apr 2010 05:33:36 GMT, "ashraf_al_ani via AccessMonster.com"
u54845@uwe wrote:

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
--

John W. Vinson [MVP]
  #3  
Old April 8th, 2010, 08:08 AM posted to microsoft.public.access.forms
ashraf_al_ani via AccessMonster.com
external usenet poster
 
Posts: 14
Default Prevent duplicate from 3 text

John W. Vinson wrote:
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

--
Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:35 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.