Microsoft Access: Format Transaction Numbers by Year and Restart the Sequence
Question details
The user needs transaction identifiers such as 2020-EXP-0001, with a sequence that restarts each year and leaves historical identifiers unchanged.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Assigning year-specific transaction numbers and displaying them with an EXP prefix and a four-digit sequence.
- Observed behavior
- Changing an AutoNumber display format affects all records rather than storing a permanent year, and it does not provide a separate sequence for each year.
Identify the transaction table, its data-entry form, and the date that determines the numbering year. Check whether multiple users create records at the same time; the simple next-number example below is suitable only for single-user entry.
Store the year and yearly sequence separately from the AutoNumber key
Use separate stored fields to restart the business sequence each year while preserving existing transaction identifiers.
An AutoNumber field should remain an internal record identifier. Its Format property controls presentation, not a reliable annual numbering sequence.
Store the assigned year and transaction number in each record. Build the readable identifier from those stored values rather than calculating the year from today's date whenever a record is displayed.
Open the transaction table in Design View. Keep the existing AutoNumber primary key, and add TransactionYear and TransactionNumber as Number fields with Field Size set to Long Integer. For established records, populate these fields from verified historical dates and numbers before making them required.
In table Design View, open Design > Indexes. Create an index named YearSequence with TransactionYear on its first row. On the next row, leave Index Name blank and select TransactionNumber. Set the index's Unique property to Yes. Once existing data is populated correctly, set both fields' Required properties to Yes.
Open the bound data-entry form in Design View. In the form Property Sheet, select Event > Before Insert > [Event Procedure], then click the build button. For single-user entry, add these lines inside Form_BeforeInsert, replacing Transactions with your table name: Me!TransactionYear = Year(Date()) Me!TransactionNumber = Nz(DMax("TransactionNumber", "Transactions", "TransactionYear=" & Me!TransactionYear), 0) + 1 This assigns 1 when the selected year has no records. If numbering follows the transaction date rather than the creation date, derive TransactionYear from that date field instead.
Open a query in Design View and enter this expression in a blank Field cell: TransactionReference: [TransactionYear] & "-EXP-" & Format([TransactionNumber],"0000") Alternatively, add a text box to a form or report and set its Control Source to: =[TransactionYear] & "-EXP-" & Format([TransactionNumber],"0000")
In the form's Design View, select the controls bound to TransactionYear and TransactionNumber and set their Locked properties to Yes. Create a test record and confirm that its displayed reference uses the stored year and sequence. Do not recalculate those fields when opening or editing historical records.

Use WPS Office to Review Exported Transaction Lists
WPS Office is a free, lightweight alternative for everyday document and spreadsheet work, with a familiar interface and Microsoft Office format compatibility for easy migration. Export your Access transaction query to an Excel file, then use WPS Spreadsheet to review or share the yearly references. WPS Office does not replace Access database logic or fix its AutoNumber behavior.

Frequently Asked Questions
Can I change the AutoNumber format to include the current year?
You can change presentation through the field's Format property in table Design View, but that format applies to all records using it. It does not store each record's original year or restart its sequence. Store TransactionYear separately to preserve historical identifiers.
How does the first transaction of a new year become 0001?
Calculate the maximum TransactionNumber only among records with the new TransactionYear. In the single-user example, Nz(DMax("TransactionNumber", "Transactions", "TransactionYear=" & Me!TransactionYear), 0) + 1 returns 1 when that year has no records. Format([TransactionNumber],"0000") displays it as 0001.
Will old transaction references change when a new year starts?
Not if the displayed reference uses the stored TransactionYear and TransactionNumber. Avoid using Year(Date()) in the display expression; use it only when assigning the year to a new record.
Is DMax plus 1 safe when several people enter transactions?
No. Simultaneous users can receive the same calculated number. Create a unique composite index on TransactionYear and TransactionNumber to reject duplicates, and use a transactionally controlled counter with locking and retry logic to allocate numbers safely.
Can WPS Office run my Access database and generate these numbers?
WPS Office does not run Access .accdb databases or their form event procedures. In Access, select the query containing your formatted references and use External Data > Excel to export it. Open the resulting spreadsheet in WPS Spreadsheet for review and reporting.




