troubleshooting Question

Trying to disallow duplicate entries in a text fiel on a form

Avatar of SteveL13
SteveL13Flag for United States of America asked on
Microsoft Access
3 Comments1 Solution110 ViewsLast Modified:
I'm using this code in an attempt to disallow duplicate entries in a form field.  But I get an error...  "Data type mismatch in criteria expression".  Note:  Serial is a text field in the table.

Private Sub txtSerial_BeforeUpdate(Cancel As Integer)

    Dim strCriteria As String

    strCriteria = "Serial = " & Me.txtSerial & ""

    If DCount("Serial", "tblEquipment", strCriteria) > 0 Then
        Me.Undo
        MsgBox "Warning: Serial " & txtSerial & " already exists." & vbCr & vbCr & "You cannot enter duplicate serial numbers.", vbInformation, "Duplicate Information"
        Cancel = True
    End If

End Sub
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros