Others

How to Calculate Quantity on Hand from Inventory Subform Records

Maira MehtabMaira Mehtab Oct 19, 2026 871 views

Question details

The user wants to accurately calculate the current quantity on hand for inventory items using incoming and outgoing data entered through stock-in subforms.

How to Calculate Quantity on Hand from Inventory Subform Records
Product
Database Management
Device & OS
not provided
Scenario
Managing inventory movements where items are received or shipped via subforms and the system needs to dynamically calculate the real-time stock balance.
Observed behavior
Stock balances need to be dynamically aggregated from a history of incoming and outgoing transaction records to ensure accurate inventory levels without relying on static, manually updated fields.
Before you start

Ensure you have a centralized transaction table configured that logs every stock movement (both incoming and outgoing) with a unique part ID, transaction type, and quantity.

Solution 1Recommended

Calculate Quantity on Hand Using Aggregate Queries

Use SQL queries to dynamically convert outgoing stock to negative values and sum the total to find the accurate quantity on hand.

Storing the quantity on hand as a fixed number can lead to data inconsistencies if transactions are edited or deleted. Instead, the best practice is to calculate it dynamically by summarizing all historical stock movements recorded in your transaction table.

1
Create a transaction table

Set up a table named 'tblTransactions' with fields for 'PartID', 'TransactionTypeID' (e.g., "I" for In, "O" for Out), and 'Qty'.

2
Build an adjustment query

Create a query to convert outgoing stock into negative numbers. Use the SQL: SELECT PartID, TransactionTypeID, IIf(TransactionTypeID = "O", Qty * -1, Qty) AS AdjQty FROM tblTransactions;

3
Create an aggregate query

Sum the adjusted quantities to get the current stock balance by using the SQL: SELECT PartID, Sum(AdjQty) AS QOH FROM qryAdjQty GROUP BY PartID;

4
Link your stock-in subform

Configure your inventory subform so that every time a new item is received or shipped, it automatically appends a new transaction record to the 'tblTransactions' table.

Calculate Quantity on Hand Using Aggregate Queries
Data Integrity: Calculating inventory dynamically ensures your Quantity on Hand is always perfectly synchronized with your real transaction history.
Free Microsoft Office alternative

Need an Easier Way to Track Inventory? Try WPS Office

If building complex database queries for inventory feels overwhelming, WPS Spreadsheet offers a lightweight, highly compatible alternative. You can easily manage incoming and outgoing stock and calculate quantity on hand using straightforward SUMIFS formulas without writing any SQL code.

  1. 1. Download and install WPS Office: Get the free WPS Office suite from the official website and install it on your device.
  2. 2. Import existing spreadsheets: Open WPS Spreadsheet to seamlessly load any existing Excel inventory trackers you have.
  3. 3. Apply inventory templates: Search the template library for 'Inventory Management' to instantly start tracking stock in and out with pre-built formulas.
100% compatible with Microsoft Excel (.xlsx) formats and formulas.Access hundreds of free, ready-to-use inventory management templates.Lightweight, fast-loading, and completely free to download.Familiar spreadsheet interface that requires zero database programming knowledge.
microsoft office alternative - wps office

Frequently Asked Questions

Why shouldn't I just store the quantity on hand as a fixed number?

Storing inventory as a fixed static number can lead to severe data corruption if a stock movement record is deleted, modified, or missed. Calculating it dynamically from a transaction log ensures your inventory level is always 100% accurate and verifiable.

How do I handle physical stock counts that differ from the database calculation?

You should utilize a dedicated 'Stock Take' table. Compare the physical count you observe to the dynamically calculated quantity, and create an adjustment transaction record to reconcile the difference without breaking the historical calculation.

Can I calculate quantity on hand using a spreadsheet instead of a database program?

Yes. In tools like WPS Spreadsheet, you can track incoming and outgoing stock in separate columns or sheets. By using functions like SUMIFS, you can easily calculate the current quantity on hand for specific items based on their unique Item IDs.