I have a database that records computer and printer equipment in the building. I have found that I have employees that will enter data into a form and leave the serial number (SerNo) field blank. I want to prevent that from happening and prevent duplicate data in this field.
On the SerNo entry in the table the properties are set to Yes (No Duplicates). I use the code below to check for duplicate data, but when the user goes back and enters a unique value the same error message comes up.
What appears to happen is once a duplicate data situation occurs it will repeat the error and never let the user continue:
Private Sub SerialNumber_BeforeUpdate(Cancel As Integer)
If DCount("serialnumber", "comprt", "[serialnumber] = '" & Me.SerialNumber & "'") > 0 Then
MsgBox "This Serial Number Already Exists!"
SerialNumber.BackColor = vbRed
Cancel = True
Exit Sub
End If
End Sub
On the SerNo entry in the table the properties are set to Yes (No Duplicates). I use the code below to check for duplicate data, but when the user goes back and enters a unique value the same error message comes up.
What appears to happen is once a duplicate data situation occurs it will repeat the error and never let the user continue:
Private Sub SerialNumber_BeforeUpdate(Cancel As Integer)
If DCount("serialnumber", "comprt", "[serialnumber] = '" & Me.SerialNumber & "'") > 0 Then
MsgBox "This Serial Number Already Exists!"
SerialNumber.BackColor = vbRed
Cancel = True
Exit Sub
End If
End Sub