Hi Guys
I have a form in which there are diff controls. What I want to do is when the user enters duplicate barcode in the textbox then an error message showing duplicate value should appear. I can't apply primary key on the table field barcode as in the table there is autonumber field present which is unique. I have wriiten the following code on the textbox lost focus event and I have used dlookup function to check for duplicate values but its not working .
Thanks in advance for your help.
Aman
I have a form in which there are diff controls. What I want to do is when the user enters duplicate barcode in the textbox then an error message showing duplicate value should appear. I can't apply primary key on the table field barcode as in the table there is autonumber field present which is unique. I have wriiten the following code on the textbox lost focus event and I have used dlookup function to check for duplicate values but its not working .
Code:
Private Sub Text17_LostFocus()
Dim Same As String
If Same = DLookup("Barcodevalue", "[Completed_table]", "Barcodevalue = Text17") Then
MsgBox "Duplicate Entry of Barcode is not allowed"
Text17.SetFocus
Exit Sub
Else
sSQL = "Insert into Completed_table(Date1,Location,Department,Barcodevalue,Signature) values (#" & Format(Me.Text4.Value, "mm-dd-yy") & "#,'" & Me.Combo12.Value & "','" & Me.Combo15.Value & "','" & Me.Text17.Value & "','No')"
DoCmd.SetWarnings False
DoCmd.RunSQL sSQL
end if
end sub
Thanks in advance for your help.
Aman