jspc
asked on
Increment Qty from Scan
Hello,
I have the attached Microsoft Access Database with two columns:
• UPC (Barcode)
• Quantity
I want to be able to scan a barcode to the database. If the same barcode is scanned I want the qty of the first scanned line item to increment to 2 rather than creating a new line.
So I want to combine the Qty column (or Sum) if the same barcode is scanned.
Are you able to help me with that? The attached database can be changed.
Thank you.
StockCount.accdb
I have the attached Microsoft Access Database with two columns:
• UPC (Barcode)
• Quantity
I want to be able to scan a barcode to the database. If the same barcode is scanned I want the qty of the first scanned line item to increment to 2 rather than creating a new line.
So I want to combine the Qty column (or Sum) if the same barcode is scanned.
Are you able to help me with that? The attached database can be changed.
Thank you.
StockCount.accdb
You can't do this in one step. First you need to use something like a dLookup() to determine of the Barcode already exists. If it exists, then you would run an update query to increment the quantity field. If it does not exist, you would run an append query to add a new record.
ASKER
Oh ok .. but I'm actually scanning the data in from each product. (This is how its added)
If I was to have the data in an Excel file (Barcodes) could it then be done?
If I was to have the data in an Excel file (Barcodes) could it then be done?
Scanning into Excel rather than an Access form just adds unnecessary complications and you have the same issue. If the Barcode exists, you need to UPDATE but if the Barcode does not exist, you need to INSERT. These are two different operations.
ASKER
I'm scanning into Access, not Excel.
I am adding all the barcodes from each stock item into an access database.
Each scan is a qty so many scans of the same product I want to consolidate those same products.
I am adding all the barcodes from each stock item into an access database.
Each scan is a qty so many scans of the same product I want to consolidate those same products.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome! That's it. Thank you so much.
ASKER
Just one other thing, are you able to tell me how to set the default Qty to equal 1 and enter automatically?
Yes:
Private Sub UPC_BeforeUpdate(Cancel As Integer)
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "UPC = '" & Me!UPC.Value & "'"
If Not rs.NoMatch Then
rs.Edit
rs!Quantity.Value = rs!Quantity.Value + 1
rs.Update
Me.Undo
Cancel = True
End If
rs.Close
If Not Cancel Then
Me!Quantity.Value = 1
End If
End Sub
I would not scan into a bound control. You don't want to dirty the current record with a duplicate barcode. If you do, you will also have to deal with that issue because you don't want Access to try to save the duplicate record.
As I suggested earlier, don't even use the form's recordset. Just run update or insert queries.
You can provide the value for the quantity in the insert as Gus suggested or you can modify the table design and set 1 as the default value for the quantity.
As I suggested earlier, don't even use the form's recordset. Just run update or insert queries.
You can provide the value for the quantity in the insert as Gus suggested or you can modify the table design and set 1 as the default value for the quantity.
Try my clever demo. There will be no duplicate barcode.
StockCount.accdb
StockCount.accdb
ASKER
I am stocktaking barcodes so there will be barcodes which are the same.
Thanks, Gustav Brock that is awesome!
My last question is, when you enter a new barcode the default qty is 1, then you need to hit the "Enter" key to accept the data. Can the "Enter" key step be automated so you don't need to touch the keyboard at all? Just scan and accept.
Thanks, Gustav Brock that is awesome!
My last question is, when you enter a new barcode the default qty is 1, then you need to hit the "Enter" key to accept the data. Can the "Enter" key step be automated so you don't need to touch the keyboard at all? Just scan and accept.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Gee your good! Thank you, that's brilliant!
You are welcome!