Reputation: 5
I have created student attendance application in MS access 2010 in which I have two main tables. One table is master data of student and other is attendance table in which field ID Card Number and Date is Primary because to avoid duplication of attendance on same day.
One form form scanning is directly attached with attendance table in which when student scan twice the below error shown on screen:
The changes you requested to the table were not successfully because the would create duplicate value in the index, primary key, or relationship. change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again
In attendance FORM I write my own message in ON ERROR
control which is working and display error but when I press okay the above screen again appear. I want to suppress the above error message.
Upvotes: 0
Views: 4885
Reputation: 123664
The following works for me:
In the Before Update
event handler for the form I have
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "Attandence of Employee Lunch", "[RFID Number]=" & Me.RFID_Number) > 0 Then
MsgBox "Primary key already exists."
Cancel = True
End If
End Sub
Note that the Cancel = True
statement cancels the update .
Upvotes: 2