How to Find Missing Invoice Numbers by Year and Type in Access
Question details
The user needs to identify missing invoice numbers in an Access database, categorized separately by year and specific invoice types such as Ordinary, Development, and Salary.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Auditing database records to ensure there are no gaps in the sequentially issued invoice numbers across different operational years and categories.
- Observed behavior
- The user requires a structured SQL query approach to output a list of missing numbers up to the maximum issued invoice number for each specific group.
Before building the queries, create a simple auxiliary table named 'tblNumbers' containing a single column with sequential numbers from 1 to at least 1000, and ensure your main invoices table is properly indexed by Year and Type.
Use a Cartesian Query and LEFT JOIN to Find Gaps
This method cross-references a baseline sequence of numbers against your actual records to identify missing invoice numbers.
To find missing sequence numbers in Access, you cannot rely on the main table alone because the missing numbers simply do not exist in the data. Instead, you generate a complete set of expected numbers and use a LEFT JOIN to see which ones fail to match your actual records.
Create a new table called 'tblNumbers' with one integer field. Populate it with sequential numbers starting from 1 up to the highest invoice number you anticipate (e.g., 1 to 1000). Also, ensure you have a table or distinct query containing your invoice types.
Create a totals query to determine the highest invoice number currently issued for each year and type. Use the SQL view to enter: SELECT InvoiceYear, InvoiceType, Max(InvoiceNo) AS MaxInvNo FROM tblInvoices GROUP BY InvoiceYear, InvoiceType;
Create a new query that includes your years, invoice types, and the 'tblNumbers' table without joining them with lines. This creates a Cartesian product, generating every possible combination of year, type, and number.
Link your Cartesian query to the main 'tblInvoices' table using a LEFT JOIN on Year, Type, and Number. In the criteria, set the invoice number from the main table to 'Is Null', and filter the 'tblNumbers' field to be '<= [MaxInvNo]' from your totals query. Run the query to display the missing numbers.

Need a Lightweight Office Suite? Try WPS Office
While WPS Office does not feature a dedicated relational database management tool like Microsoft Access, it serves as an excellent, free alternative for handling all your document, spreadsheet, and presentation needs with exceptional Microsoft Office compatibility.
- 1. Download the Installer: Visit the official WPS Office website to download the free installation package for your operating system.
- 2. Install WPS Office: Run the downloaded installer and follow the simple on-screen instructions to set up the software.
- 3. Open Existing Office Files: Launch WPS Office to instantly open, edit, and save your existing Word documents, Excel spreadsheets, and PowerPoint presentations without losing formatting.

Frequently Asked Questions
What is a numbers table and why is it needed in Access?
A numbers table (or tally table) is an auxiliary table that holds a continuous sequence of integers. It is required in queries that look for missing data gaps, as relational databases cannot evaluate records that do not exist without a baseline sequence to compare them against.
Why use a Cartesian query for finding missing records?
A Cartesian query, or cross join, combines every row from one table with every row from another. By combining years, types, and sequence numbers, it generates a complete master list of all expected invoices, which is then compared against your actual data.
How does the LEFT JOIN isolate the missing invoice numbers?
A LEFT JOIN returns all records from the left side (your generated master list) and matching records from the right side (your actual invoices). When an invoice is missing, the right side returns a null value. By setting a filter condition to only show nulls on the right side, the query perfectly isolates the missing numbers.




