M A
asked on
Custom autonumber format in access
I am trying to have custom autonumber and found the below url helpful.
https://www.experts-exchange.com/questions/23238522/Looking-for-custom-autonumber.html
Is there anyone who can help to make it in this format JBddmmyy-1 or JBddmmyyxx
eg. JB021213-01, JB021213-02, JB021213-03
or
eg. JB02121301, JB02121302, JB02121303
i.e each day it will start from 01 with that date format
eg. JB031213-01, JB031213-02, JB031213-03 for tomorrow
Is there anyone who can make the changes and upload it here or post the code here
https://www.experts-exchange.com/questions/23238522/Looking-for-custom-autonumber.html
Is there anyone who can help to make it in this format JBddmmyy-1 or JBddmmyyxx
eg. JB021213-01, JB021213-02, JB021213-03
or
eg. JB02121301, JB02121302, JB02121303
i.e each day it will start from 01 with that date format
eg. JB031213-01, JB031213-02, JB031213-03 for tomorrow
Is there anyone who can make the changes and upload it here or post the code here
ASKER
Thanks for your code.
Can you upload an access2007/2010 DB as I tried and ended up in error.
Appreciate your help
Can you upload an access2007/2010 DB as I tried and ended up in error.
Appreciate your help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is the error I am getting now
"You can't go to the specified record"
and the below line is highlighted in yellow
DoCmd.GoToRecord , , acNewRec
"You can't go to the specified record"
and the below line is highlighted in yellow
DoCmd.GoToRecord , , acNewRec
ASKER
Many thanks to both
I appreciate if you can explain what your code does.
Just want to know. Please explain when you are free.
I appreciate if you can explain what your code does.
Just want to know. Please explain when you are free.
The following line formats the date as ddmmyy with JB at the beginning. For instance, todays' date is stored in the variable sPrefix as JB021213:
This next line looks only at the records in your table where your ID field begins with the same prefix as what is stored in the variable (using the LIKE keyword and a wildcard '*'). It gets the maximum value of the last 2 characters and adds 1 to that value. If there is no record yet for the day, the NZ function tells it to return a 0 (which ends up having a 1 added to it).
Finally, this line returns the prefix concatenated with the next sequence number wich is formatted to show two numeric places and a dash at the beginning.
Ron
sPrefix = Format(Date, "JBddmmyy")
This next line looks only at the records in your table where your ID field begins with the same prefix as what is stored in the variable (using the LIKE keyword and a wildcard '*'). It gets the maximum value of the last 2 characters and adds 1 to that value. If there is no record yet for the day, the NZ function tells it to return a 0 (which ends up having a 1 added to it).
bSeq = Nz(DMax("Right([ID],2)", "TableName", "[ID] LIKE '" & sPrefix & "*'"), 0) + 1
Finally, this line returns the prefix concatenated with the next sequence number wich is formatted to show two numeric places and a dash at the beginning.
GetNextSeq = sPrefix & Format(bSeq, "-00")
Ron
ASKER
I am confused of which will check whether the record is there or no?
Can you post the code which will check the for record availability.
if the record there which coding adding +1
Can you post the code which will check the for record availability.
if the record there which coding adding +1
If the record doesn't exist for that day, the DMax function will return a NULL value. Hence Nz(DMax("Right([ID],2)", "TableName", "[ID] LIKE '" & sPrefix & "*'"), 0) will become Nz(NULL, 0). The Nz function in this instance will default to 0 and since we always add 1 to the result, you will get a Sequence starting at 1 whenever the record doesn't exist.
Ron
Ron
pls try
Open in new window
Regards