Prevent duplicates in multiple fields (1 Viewer)

aftab1965

Registered User.
Local time
Today, 05:31
Joined
Jan 12, 2016
Messages
48
Dear Friend I need your help.
I have a database "Student" having only one table "Registration" which has "ID, Studentname, FatherName, Class and Group" Fileds, and A Form "frm_reg"

I want to prevent duplication of records, while entering data into "frm_reg" form in multiple field.


Sample data is attached herewith.
 

Attachments

  • student.accdb
    600 KB · Views: 174

Ranman256

Well-known member
Local time
Yesterday, 21:31
Joined
Apr 9, 2015
Messages
4,337
Key the table on those fields, then no more dupes.
 

sneuberg

AWF VIP
Local time
Yesterday, 18:31
Joined
Oct 17, 2014
Messages
3,506
After you decide what constitutes a duplicate you can check for that condition in the form's before update. Below is an example of what the form's before update might look like if duplicate combinations of StudentName and FatherName were considered duplicate records.


Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

If DCount("*", "registration", "StudentName = '" & Me.StudentName & "' AND FatherName = '" & Me.FatherName & "'") > 0 Then
    MsgBox "The combination of student name and father name must be unique"
    Me.FatherName.SetFocus
    Cancel = True
End If

End Sub
 

Users who are viewing this thread

Top Bottom