Others

Use a USB Barcode Scanner for Microsoft Access Inventory

Elise WilliamsElise Williams Nov 14, 2026 871 views

Question details

Set up a USB barcode scanner to find products, reduce stock, and record inventory transactions in Microsoft Access.

Use a USB Barcode Scanner for Microsoft Access Inventory
Product
Microsoft Access
Device & OS
not provided
Scenario
A user wants to scan product barcodes into an inventory form and keep a transaction history.
Observed behavior
The desired setup accepts a scanned code, finds the matching product, reduces its quantity by one, and records the change.
Before you start

Confirm that the USB scanner is configured for keyboard input by scanning a barcode into a text field. Check whether it sends Enter or Tab after the code, and ensure your Access database can run VBA.

Solution 1Recommended

Create an Access form that processes barcode scans

Use a scan field and a button to reduce stock by one and save a transaction for each valid scan.

A keyboard-style scanner enters text into a focused text box; you do not need a barcode display control to receive the scan. The example below stores quantities in the Products table and records changes in a Transactions table.

This example processes one item per button click and prevents stock from falling below zero. Table, field, and control names must match the names in the code.

1
Create the product table

In Access, select Create > Table Design and save a table named Products. Add ProductID as an AutoNumber primary key, Barcode as Short Text, ProductName as Short Text, and StockQuantity as Number with Field Size set to Long Integer. Make Barcode required and indexed with no duplicates, and set StockQuantity as required with a default value of 0. Add optional cost and location fields as needed.

2
Create the transaction table

Use Create > Table Design to save a table named Transactions. Add TransactionID as an AutoNumber primary key, Barcode as Short Text, TransactionDate as Date/Time, UserName as Short Text, and QuantityChange as Number with Field Size set to Long Integer. Set Barcode, TransactionDate, and QuantityChange to required.

3
Add scan controls

Open the inventory form in Design View. Add an unbound text box named txtBarcode and a command button named cmdProcessScan, with a caption such as Process Scan. Save the form.

4
Add the processing code

Select cmdProcessScan, open Property Sheet > Event, and set On Click to [Event Procedure]. Select the ellipsis button and insert this code inside the generated event procedure: Dim db As DAO.Database Dim ws As DAO.Workspace Dim code As String Dim safeCode As String Dim safeUser As String Dim inTransaction As Boolean On Error GoTo HandleError code = Trim(Nz(Me.txtBarcode.Value, "")) If code = "" Then MsgBox "Scan a barcode first." Exit Sub End If safeCode = Replace(code, "'", "''") safeUser = Replace(Environ("Username"), "'", "''") Set ws = DBEngine.Workspaces(0) Set db = CurrentDb ws.BeginTrans inTransaction = True db.Execute "UPDATE Products SET StockQuantity = StockQuantity - 1 " & _ "WHERE Barcode = '" & safeCode & "' AND StockQuantity > 0", dbFailOnError If db.RecordsAffected <> 1 Then ws.Rollback inTransaction = False MsgBox "Barcode not found or stock is zero." Exit Sub End If db.Execute "INSERT INTO Transactions " & _ "(Barcode, TransactionDate, UserName, QuantityChange) VALUES ('" & _ safeCode & "', Now(), '" & safeUser & "', -1)", dbFailOnError ws.CommitTrans inTransaction = False Me.txtBarcode = Null MsgBox "Stock updated and transaction recorded." Exit Sub HandleError: If inTransaction Then ws.Rollback MsgBox "The scan could not be processed: " & Err.Description

5
Test a scan

Open the form in Form View, select txtBarcode, scan a known product, and click Process Scan. Open the Products and Transactions tables to confirm that stock decreased by one and a transaction was added. Test an unknown barcode and a product with zero stock; neither should create a transaction.

Create an Access form that processes barcode scans
User identification: The example records the Windows username returned by Environ. If you need verified application users, replace it with your database's authenticated user value.
Free Microsoft Office alternative

Track inventory in a WPS spreadsheet

For a simpler spreadsheet-based inventory, WPS Office is a free, lightweight alternative with a familiar interface. Open compatible Excel files to migrate spreadsheet records, though WPS does not replace Access forms or run the Access VBA procedure above.

Use spreadsheet rows to review product codes and stock quantities.Open and edit Microsoft Excel formats such as XLSX.Work in a familiar, easy-to-use interface.Move existing spreadsheet data into a lightweight Office alternative.
microsoft office alternative - wps office

Frequently Asked Questions

Do I need a special barcode control on the Access form?

No. If the scanner acts as a keyboard, select an ordinary unbound text box on the form and scan into it. A barcode display control is not needed to receive the code.

How do I keep leading zeros in product barcodes?

In Products table Design View, set Barcode to Short Text rather than Number. Store the full code in that field and scan it into a text box.

What happens if the barcode is missing or the stock is zero?

The example's update query finds no eligible product, rolls back the transaction, and displays a message. It does not add a Transactions row.

Can the scanner process a code without clicking the button?

Yes, but it requires additional form setup. For example, configure the scanner to send a suffix and use an appropriate form event to call the processing routine. Test the focus and event behavior before using it for live inventory.

Why should Barcode be indexed with no duplicates?

A unique index in Products table Design View ensures that one scanned barcode identifies at most one product. The example expects exactly one matching stock row.