Hi, I'm a relative newcomer to Access, VBA & SQL programming, and have had to basically figure my way along. I am putting together a database which will allow me to scan in barcodes from a product that we are building, check the unit serial number against test data in our SQL Server to ensure the unit did pass it's end-of-line function test, and then concatenate the whole lot of serial numbers into a string together with a lot number which identifies which production line it came from and the "Julian Date" it was packaged on. So far, so good, pretty simple (sarcasm). But got it all working pretty well for a first go, I'm sure there's a lot of fat I can trim out as I "mature", but it's functional. I basically have 2 problems left to resolve before I can unleash it on the world. The first is in the inital Form which the operator uses to scan in a new barcode. This Form breaks the barcode into a Part Number, and Serial Number, and verifies that the Serial Number is not a duplicate. It was easy enough to format the table that I'm dumping the Part Number and Serial Number into to be indexed without duplicates. IF I scan in a duplicate number I get the standard Access warning that no records could be appended due to a key violation. However, I would like to compare that new serial number that's been scanned into the text box on my Form with the existing records in the table which will receive this data and see if it already exists, and then output a message telling the operator specifically that he is trying to input a duplicate Serial Number (rather than having him guess what the meaning of that message is). Here is the code I have to transfer the barcode data from the Form to the Table. Any recommendations on code to do that comparison and output a True/False result would be greatly appreciated. I know how to construct a IF THEN statement and even the output message (as shown), just can't get the comparison logic.
Public Sub Command15_Click()
Dim HousingID As String
Dim SerialNumber As String
HousingIDText.SetFocus
HousingIDString = HousingIDText.Text
'DoCmd.SetWarnings (False)
DoCmd.RunSQL ("Insert into tempHousingIDScan ([HousingID]) Values ('" + HousingIDString + "')")
DoCmd.RefreshRecord
DoCmd.SetWarnings (True)
'------------------------------
'If HousingIDText = "tempHousingIDScan.HousingID" Then
'Err.Description = "Duplicate Serial Number Found, Scan Different Label!"
'MsgBox (Err.Description)
'End If
HousingIDText.SetFocus
HousingIDText = " "
End Sub
I'll describe the second problem in a new post so as to keep this from getting too much longer.... Thanks for any help!