Others

How to Find Missing Invoice Numbers by Year and Type in Access

Bushra ParveenBushra Parveen Nov 2, 2026 869 views

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.

How to Find Missing Invoice Numbers by Year and Type in Access
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 you start

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.

Solution 1Recommended

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.

1
Create a Reference Table for Numbers

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.

2
Query the Maximum Invoice Number per Group

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;

3
Build a Cartesian Join

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.

4
Apply a LEFT JOIN to Filter Missing Numbers

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.

Use a Cartesian Query and LEFT JOIN to Find Gaps
Number Table Sizing: Ensure your 'tblNumbers' table contains enough rows to cover the maximum possible invoice number. If an invoice reaches number 1001 and your table only goes to 1000, the query will not evaluate beyond 1000.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website to download the free installation package for your operating system.
  2. 2. Install WPS Office: Run the downloaded installer and follow the simple on-screen instructions to set up the software.
  3. 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.
Completely free and lightweight Office suiteFully compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx) formatsBuilt-in PDF editor for reading, converting, and editing PDF filesFamiliar user interface for seamless and intuitive migration
microsoft office alternative - wps office

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.