Format [AutoNumber] & Restart at particular condition (1 Viewer)

mfaisal.ce

Member
Local time
Today, 08:56
Joined
Dec 21, 2020
Messages
76
Dear All,

I have a Parent/child tables...

Parent Table: Sales (SNo)
Child Table : Sales_Detail (SNo)
Child Table : Sales_Payment (SNo)
Child Table : Sales_Return (SNo)

Each Parent Record has multiple Child records in each table....
Each Child Table has column SrNo column with AutoNumber format.

1. what i need is; SrNo [AutoNumber] restarts with each SNo and does not continue as new record in Child Table
2. I need to Format SrNo [AutoNumber] as SNo-SrNo

Example,


If SNo is 1, then SrNo for all child records in Sales_Detail Table should be like
1-1
1-2
1-3
1-4
and if SNo is 2, then it should be like this
2-1
2-2
2-3
2-4

Database File is attached, plz find any solution if possible...

regards,
 

Attachments

  • Faisal.accdb
    1.7 MB · Views: 454

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:56
Joined
Oct 29, 2018
Messages
21,477
Unfortunately, I don't think Autonumber fields can restart. So, if that's what you want, you may have to stop using Autonumber fields.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:56
Joined
May 7, 2009
Messages
19,247
you can use a Query for your tables.
adding a Calculated Column that will concat the "parent" sno and the
"child" sno.

use the query as rowsource of your form/subform.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:56
Joined
Feb 28, 2001
Messages
27,194
An autonumber is wrong for this application. Autonumbers must remain unique AND there is the problem that an autonumber can skip a number sometimes based on failed or retracted update attempts. You want a "custom autonumber" so perhaps this article will help:

 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:56
Joined
Feb 19, 2002
Messages
43,302
Leave the autonumber as the PK for the table and use it in any relationships. The following is a couple of examples of how to make your own "intelligent" sequence numbers.

For the use you suggested, I would NOT create a custom sequence number but here's the code anyway.
 

Attachments

  • CustomSequenceNumber20201020c.zip
    85.6 KB · Views: 474

Users who are viewing this thread

Top Bottom