Others

Reset Subform Numbering for Each New Master Record in Access

Natalie TaylorNatalie Taylor Oct 22, 2026 869 views

Question details

The user needs the displayed numbering in Access subforms to restart at 1 whenever a new master record is created, without breaking the underlying database structure.

How to Reset Subform Numbering for Each New Master Record in Access
Product
Microsoft Access
Device & OS
not provided
Scenario
Setting up a master-detail relationship in an Access database where sub-records require localized, sequential business numbering.
Observed behavior
The subforms currently rely on AutoNumber fields, which continuously increment globally across the entire table instead of resetting for each new master record.
Before you start

Before modifying your form's numbering logic, ensure you have identified the exact field name of your Master Record ID and Subform Table, as you will need to reference them in your VBA code.

Solution 1Recommended

Add a Custom Sequential Field Using VBA and DMax

Retain the AutoNumber for primary keys and use a VBA macro on the subform's 'Before Insert' event to calculate the next sequence number per master record.

Microsoft Access AutoNumber fields are designed exclusively to generate unique system identifiers to maintain relational database integrity, not to provide sequentially perfect line numbers. To achieve numbering that resets for each master record, you should add a standard Number field to your subform's underlying table and populate it dynamically.

1
Add a Number field to the table

Open the subform's underlying table in Design View and add a new field with the Data Type set to 'Number' (for example, name it 'LineNum').

2
Update the subform design

Open your subform in Design View, open the 'Add Existing Fields' pane, and drag your newly created 'LineNum' field onto the form.

3
Access the Before Insert event

Open the subform's Property Sheet, navigate to the 'Event' tab, locate the 'Before Insert' property, and click the ellipsis (...) to open the VBA editor.

4
Write the DMax calculation code

Enter the following VBA code to find the highest line number for the current master ID and increment it by 1: Me.LineNum = Nz(DMax("LineNum", "YourSubformTable", "MasterID = " & Me.MasterID), 0) + 1

5
Save and test the subform

Save your VBA code, switch back to Form View, and add new records to verify that the line numbers increment locally and restart at 1 when a new master record is created.

Add a Custom Sequential Field Using VBA and DMax
Preserve Data Integrity: By keeping the original AutoNumber field as a hidden primary key, you maintain stable database relationships while achieving the exact visual sequential numbering you need.
Free Microsoft Office alternative

Try WPS Office for Your Data and Document Needs

While Microsoft Access is a powerful tool for complex relational databases, WPS Office provides an exceptional, lightweight alternative for managing standard flat data through advanced spreadsheets, alongside full-featured document and presentation tools. It requires no complex VBA scripting for basic sequential data tracking.

  1. 1. Download the installer: Visit the official WPS Office website and 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 complete the setup.
  3. 3. Manage your data: Open WPS Spreadsheets to easily manage, organize, and sequence your database records using intuitive formulas.
Highly compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx) formatsLightweight and runs smoothly on Windows, Mac, Linux, and mobile devicesRich built-in spreadsheet functions for complex data tracking and numbering without codingFree to download and use with a clean, intuitive, and familiar tabbed interface
microsoft office alternative - wps office

Frequently Asked Questions

Why shouldn't I just reset the AutoNumber field in Access?

AutoNumber fields are designed exclusively to provide unique identifiers for database records to maintain referential integrity. Attempting to force them to reset or behave sequentially per master record can lead to duplicate primary keys, broken relationships, and severe database corruption.

Can I use a query instead of VBA to generate sequential subform numbers?

Yes, you can create a query that calculates the sequence using a subquery. The subquery counts the number of records with the same master ID that have a lesser or equal primary key. However, VBA is generally preferred for data entry forms as it generates the number instantly upon insertion.

What happens if I delete a row in the sequentially numbered subform?

If you use the DMax VBA method, deleting a row will not automatically renumber the remaining rows, leaving a gap in your sequence. If strict gapless numbering is required after deletions, you would need to write an additional update query or VBA routine to recalculate the sequence for all related sub-records.