Check if duplicate afterupdate

Ross Hurrell

Registered User.
Local time
Today, 23:15
Joined
Nov 17, 2006
Messages
11
Hi, I was wondering if anyone knows the VB to check if a value is a duplicate afterupdate?

Many thanks.
 
Do you mean after or before update? I only ask as it's safer to stop the record being inserted than to delete it afterwards.

Either way, you can use DCount() for that record in the relevant table. If it returns more than zero, you've got a duplicate.
 
Afterupdate or beforeupdate. Not too sure.

Like, I have TEXTBOX1 and i enter a number that already exists within TABLE1. I would like it to pop a message up "This number already exists" and would keep doing so untill i enter a number that doesnt exsit.

Thanks
 
You want to use the beforeupdate event for this. That way you can cancel the update if the number is found. I would use the Dlookup or DCount functions to query the table to see if the number exists.
 
Im having real trouble trying to create some code to get this to work.

So far I have:

If DCount("BARCODE", "Inbound parcels") > 0 Then
MsgBox "This Barcode has already been used"

BARCODE is the textbox and "Inbound parcels" is my Table.
 
if Dcount([FieldName],"[Inbound parcels]","[FieldName]='" & me.Barcode & "'")

the above should work if the field is a text field
 
If DCount([BARCODE], "[Inbound parcels]", "[Barcode]='" & Me.BARCODE & "'") > 0 Then
MsgBox "This Barcode has already been used"
End If

Hmm.. I am using that and now it seems to only let Barcodes with just numbers through the system,
Some of my barcodes have letters and it shows:

"Run time 2001 error"
"You canceled the previous operation"
 

Users who are viewing this thread

Back
Top Bottom