Avatar of SteveL13
SteveL13
Flag for United States of America asked on

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

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

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
SteveL13

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott McDaniel (EE MVE )

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Gregory Miller

Which line is giving you the error you mention?
SteveL13

ASKER
Perfect!  Thank you.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck