code to refrain from duplicate entry

richardplr

Registered User.
Local time
Today, 16:50
Joined
Jun 10, 2003
Messages
239
Hi

Please help. I have create the below code in red but what is the mistake.

If DCount("[product_code]", "PRODUCT MASTERLIST", "[product code]"= " & Me.Product_code& "'") Then
MsgBox "This Product Code has already exists!!"
Cancel = True
Me.Undo
Exit Sub
Else 'Do nothing
End If

Thank you
 
If DCount("[product_code]", "[PRODUCT MASTERLIST]", _
"[product code] = '" & Me.Product_code& "'") Then
 
RuralGuy said:
If DCount("[product_code]", "[PRODUCT MASTERLIST]", _
"[product code] = '" & Me.Product_code& "'") Then


Hi Thank you for your help but I still got error, Please see below whole coding


Private Sub Product_Code_BeforeUpdate(Cancel As Integer)
If DCount("[product_code]", "[PRODUCT MASTER LIST]", "[product code] = '" & Me.Product_code& "'") Then
MsgBox "This Product Code has already exists!!"
Cancel = True
Me.Undo
Exit Sub
Else 'Do nothing
End If
End Sub
 
You didn't mention what error you are getting. Try this:
Code:
Private Sub Product_Code_BeforeUpdate(Cancel As Integer)
If DCount("[product_code]", _
   "[PRODUCT MASTER LIST]", _
   "[product_code] = '" & Me.Product_code & "'") Then
   MsgBox "This Product Code has already exists!!"
   Cancel = True
   Me.Undo
Else 'Do nothing
End If
End Sub
 
RuralGuy said:
You didn't mention what error you are getting. Try this:
Code:
Private Sub Product_Code_BeforeUpdate(Cancel As Integer)
If DCount("[product_code]", _
   "[PRODUCT MASTER LIST]", _
   "[product_code] = '" & Me.Product_code & "'") Then
   MsgBox "This Product Code has already exists!!"
   Cancel = True
   Me.Undo
Else 'Do nothing
End If
End Sub

Great work

Thanks.
 

Users who are viewing this thread

Back
Top Bottom