Prev: DISABLED FORM
Next: Button form control does not work
From: ashraf_al_ani via AccessMonster.com on 8 Apr 2010 01:33 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
From: John W. Vinson on 8 Apr 2010 02:14 On Thu, 08 Apr 2010 05:33:36 GMT, "ashraf_al_ani via AccessMonster.com" <u54845(a)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]
From: ashraf_al_ani via AccessMonster.com on 8 Apr 2010 03:08 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
|
Pages: 1 Prev: DISABLED FORM Next: Button form control does not work |