How to Find Missing Invoice Numbers by Year in Microsoft Access
Question details
The user needs to identify gaps in sequential invoice numbers categorized by specific years within a Microsoft Access database.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Auditing or verifying consecutive invoice records over multiple years to quickly locate any skipped or missing invoice numbers.
- Observed behavior
- The goal is to generate an accurate list of missing invoice numbers uniquely filtered and bounded by the minimum and maximum invoice numbers for each corresponding year.
Verify that your Access database table and field names do not contain spaces or special characters to prevent SQL syntax errors, or prepare to wrap them in square brackets during queries.
Use Tally Tables and a Left Join Query
Create sequential reference tables to cross-check against your actual invoice table and dynamically identify numerical gaps.
This approach uses a combination of two helper tables: one for the relevant years and another containing sequential numbers. By generating a Cartesian product of these tables limited to the actual minimum and maximum invoice numbers per year, you can compare expected numbers with your database to pinpoint the missing entries.
Create a one-column table named 'InvoiceYears' containing all relevant years (e.g., 2019, 2020). Next, create a one-column table named 'InvoiceNumbers' populated with sequential numbers starting from 1 up to a value exceeding your highest expected invoice number.
Navigate to the 'Create' tab, select 'Query Design', and switch to 'SQL View'. Write a SELECT query that pulls from both InvoiceYears and InvoiceNumbers. Use the WHERE clause with subqueries to restrict the numbers so they fall between the MIN and MAX invoice numbers for that specific year. Save this query as 'qryYearNumbers'.
Create a new query and establish a LEFT JOIN connecting 'qryYearNumbers' to your actual 'Invoices' table. Ensure you link them using both the InvoiceYear and InvoiceNumber fields.
In the query designer criteria for the Invoices.InvoiceNumber field, enter 'Is Null'. Add sorting by InvoiceYear and InvoiceNumber, then run the query. The output will display all missing invoice numbers within your specified ranges.

Looking for a Lightweight Alternative for Office Data Tasks?
While Microsoft Access is built for complex relational databases, most daily data tracking, invoice sequencing, and document management can be handled effortlessly with WPS Office. As a free, lightweight, and highly compatible alternative to Microsoft Office, WPS Spreadsheet makes it easy to track numerical gaps without complex SQL queries.
- 1. Download and Install: Get WPS Office for free from the official website and install it on your preferred device.
- 2. Open Your Exported Data: Export your Access data to an Excel or CSV file and open it seamlessly in WPS Spreadsheet.
- 3. Analyze Data Gaps: Use conditional formatting or standard logical functions within the spreadsheet to highlight and identify missing invoice numbers visually.

Frequently Asked Questions
Can I use DMin and DMax functions in Access to find missing numbers?
Yes, you can use the DMin and DMax domain aggregate functions within your queries to dynamically determine the minimum and maximum invoice numbers for each year. This ensures your tally table only checks for gaps within the actual range of your recorded data.
What is a tally table in Microsoft Access?
A tally table, or numbers table, is a simple one-column database table containing sequential numbers (for example, 1 to 100,000). It is a highly efficient tool in SQL queries for generating numerical sequences, splitting strings, or identifying missing records like sequential invoice numbers.
Why do my Access queries fail when my table names have spaces?
When table or field names contain spaces or special characters, the Access SQL parser cannot interpret them correctly as single entities unless they are enclosed in square brackets. Using [Invoice Numbers] instead of Invoice Numbers resolves this syntax issue.
How can I avoid generating unnecessary missing numbers beyond my highest invoice?
By applying MIN and MAX subqueries or domain functions to your Cartesian join, you restrict the query so it only generates and checks numbers that fall strictly between the first and last actual invoice numbers issued in any given year.




