Prevent duplicates in multiple fields

aftab1965

Registered User.
Local time
Today, 14:10
Joined
Jan 12, 2016
Messages
53
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

Key the table on those fields, then no more dupes.
 
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

Back
Top Bottom