Hello everyone.
I'm trying to check for duplicate item names when adding a new item in a form.
I created an beforeupdate event but I'm getting an error and can't see why.
I'm using the DCount function.
Code:
Private Sub Part_Name_BeforeUpdate(Cancel As Integer)
Dim criteria As String
criteria = _
"Part_Name = " & Me.Part_Name & " "
If DCount("Part_Name", "Part_Database", criteria) > 0 Then
MsgBox "This Part already exists, please Add a diferent part name or edit the Existing Part"
Me.Undo
End If
End Sub
I get a Run-time error 2471:
the expression you entered as a query parameter produced this error:
"testname"
if I change the code to:
Code:
If DCount("Part_Name", "Part_Database", Me.Part_Name) > 0 Then
MsgBox "This Part already exists, please Add a different part name or edit the Existing Part"
Me.Undo
End If
this if statement is always true.
Can anyone give me a hand with this?
I did the same but using ID and it worked, but can't use IDs for this one.
Thanks so much