Restart Microsoft Access Purchase Order Numbers Every December
Question details
Create purchase order numbers that restart on December 1 while retaining a unique record key.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A purchase order database uses AutoNumber as its primary key but needs a separate sequence for each accounting year.
- Observed behavior
- Each accounting year should have its own purchase order sequence, with the accounting year stored alongside the sequence number.
Identify the purchase order table and any required fields that must be supplied when a record is created. Decide whether the accounting-year label should represent the year in which the period starts or ends; the example below uses the starting year.
Use DMax with an accounting-year field and a unique index
Use this approach to restart the purchase order sequence on December 1 and prevent duplicate year-and-number combinations.
The example labels December 1, 2025 through November 30, 2026 as accounting year 2025. Keep the existing AutoNumber field as the primary key; the accounting year and sequence are a separate business identifier.
DMax finds a candidate number, but two users can find the same candidate before either record is saved. A unique index rejects the duplicate, and the insertion code must retry after error 3022.
Open the purchase order table in Design View. Add AccountingYear and SequenceNo as Number fields with the Long Integer field size, and set both fields to Required. The example assumes the table is named PurchaseOrders.
In table Design View, open Indexes. Enter an index name such as UX_OrderYearSequence, select AccountingYear on the first row and SequenceNo on the next row with the index name left blank, and set the index's Unique property to Yes. Save the table; resolve any existing duplicate combinations first.
Open the VBA editor with Alt+F11, choose Insert > Module, and add the function below. It calculates the starting year, finds the next sequence in that year, and retries a duplicate-key conflict up to five times. Public Function CreatePurchaseOrder() As Long Dim orderDate As Date Dim accountingYear As Long Dim nextNo As Long Dim attempt As Long Dim errNo As Long Dim errDescription As String orderDate = Date accountingYear = Year(orderDate) If Month(orderDate) < 12 Then accountingYear = accountingYear - 1 For attempt = 1 To 5 nextNo = Nz(DMax("SequenceNo", "PurchaseOrders", _ "AccountingYear=" & accountingYear), 0) + 1 On Error Resume Next CurrentDb.Execute "INSERT INTO PurchaseOrders " & _ "(AccountingYear, SequenceNo) VALUES (" & _ accountingYear & ", " & nextNo & ")", dbFailOnError errNo = Err.Number errDescription = Err.Description Err.Clear On Error GoTo 0 If errNo = 0 Then CreatePurchaseOrder = nextNo Exit Function ElseIf errNo <> 3022 Then Err.Raise errNo, "CreatePurchaseOrder", errDescription End If Next attempt Err.Raise vbObjectError + 1000, "CreatePurchaseOrder", _ "Could not assign a unique purchase order number after five attempts." End Function
Update the INSERT statement and function arguments to supply any other required purchase order fields, then call CreatePurchaseOrder from the action that creates an order. Test dates on both sides of December 1 and test simultaneous inserts from separate Access sessions.

Track purchase orders in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar interface for working with Office files. Use WPS Spreadsheets for purchase order lists and migrate Excel workbooks easily; it does not run Access databases or fix Access DMax code.

Frequently Asked Questions
Why store the accounting year with the purchase order number?
The same sequence number can occur in different years. Store AccountingYear and SequenceNo together and create a unique index on both fields to identify each business number.
Can I keep AutoNumber as the primary key?
Yes. Keep the AutoNumber field as the primary key and use separate AccountingYear and SequenceNo fields for the purchase order number that restarts each year.
Does DMax alone prevent two users from getting the same number?
No. Two users can read the same maximum before either saves. Create a unique index on AccountingYear and SequenceNo, then handle duplicate-key error 3022 by recalculating and retrying the insert.
What happens when the date reaches December 1?
In the example, the accounting-year label changes to the current calendar year. DMax then searches that year's records, returning a starting sequence of 1 if none exist.
Will this method produce a gap-free sequence?
No. Deletions and other record changes can leave gaps, and deleting the highest number can cause DMax to reuse it. Use a different controlled numbering process if gap-free or never-reused numbers are required.




