Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Check for duplicate values in field

$
0
0
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

Viewing all articles
Browse latest Browse all 13329

Trending Articles