Link to home
Start Free TrialLog in
Avatar of jspc
jspcFlag for Australia

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
Avatar of PatHartman
PatHartman
Flag of United States of America image

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.
Avatar of jspc

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?
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.
Avatar of jspc

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.
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jspc

ASKER

Awesome! That's it. Thank you so much.
Avatar of jspc

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

Open in new window

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.
Try my clever demo. There will be no duplicate barcode.
StockCount.accdb
Avatar of jspc

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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jspc

ASKER

Gee your good! Thank you, that's brilliant!
You are welcome!