Create Access SQL Server Job Numbers Without Unused IDs
Question details
Create job numbers for an Access application backed by SQL Server without allocating numbers when users cancel a form.

- Product
- Microsoft Access and SQL Server
- Device & OS
- not provided
- Scenario
- An Access form uses data from a crosstab query after migration to SQL Server, and its job number is derived from an ID.
- Observed behavior
- An AutoNumber or identity value may not be available when the form opens, while generating a number before confirmation can leave it unused if the user cancels.
Identify the table that stores jobs, the components of the job number, and whether numbering is global or separate for each job type. Check that you can modify the SQL Server database and the Access form's save or confirmation action.
Assign the job number in a SQL Server transaction
Use a table-based counter and allocate a number only when the user confirms the job.
Keep the crosstab for display if needed, but submit the underlying job data through an editable form or a separate save action. Do not allocate the job number when the form opens.
The counter update and job insert must occur in the same SQL Server transaction so a failed insert rolls back the allocation. Avoid DMax for multiuser number generation because concurrent users can retrieve the same maximum value.
In SQL Server Management Studio, create a counter table with a key for each numbering series, such as job type, and a column holding its last assigned number. Initialize each series before users submit jobs.
In SQL Server Management Studio, create a stored procedure that starts a transaction, locks and increments the appropriate counter row, inserts the job using that number, and commits. Add error handling that rolls back the transaction if the operation fails.
In the Access form's confirmation button On Click event, validate the entered values and call the stored procedure with the job details. Retrieve the assigned number from the procedure and display it after the save succeeds.
Open the form and cancel before confirming; verify that the counter has not changed. Then submit jobs from two sessions and check the job table for distinct, consecutive committed numbers.

Keep the crosstab for display and save through a separate form
Use this approach when the crosstab-based form cannot provide an editable record or an identity value at opening.
Review Exported Job Data with WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface. Open exported job data in WPS Spreadsheets for an easy transition between Office files; it does not replace the Access and SQL Server transaction needed to assign job numbers.

Frequently Asked Questions
Why shouldn't I generate the job number when the form opens?
If the user closes or cancels the form, a number allocated at opening may never be used. Generate it in the confirmation or save action instead.
Can I use DMax to find the next job number?
DMax is risky in a multiuser application because two users can read the same maximum before either saves. Use a SQL Server counter table and transaction to serialize allocations.
Will a SQL Server identity column guarantee consecutive job numbers?
No. Identity values can have gaps, including after failed or rolled-back inserts. Use a transactional counter if the business requires consecutive numbers for committed jobs.
What if my Access crosstab form is not editable?
Keep the crosstab for display and enter job details on a separate form. Call a SQL Server save procedure from the form's confirmation button, then requery the display.
What happens if a job is canceled after it has been saved?
Its committed number has already been assigned. Keep the job record and mark it canceled if you need to preserve an auditable sequence rather than deleting it.




