Creating Auto number incorporating the year

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajendran r
    New Member
    • Jan 2013
    • 9

    Creating Auto number incorporating the year

    I wish to create Auto number (serial number ) in the format which includes the current year i.e., 20130001, 20130002...
    And by next it should automatically update the auto number as 20140001, 20140002
    How can write code for the above?
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Outright request for code is not allowed - please see the FAQ.

    However, as you are still new, if you will post your current efforts, we'll gladly take a look and help you get the code working.

    As for this particular topic, a search on this site will turn up several threads covering this exact topic (or at least the concept)... some very recently! :)

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      As Z says, writing the code for you would break our rules. It would also be pretty hard as you include so little detail in the question. However, I can tell you the concept you will need to understand and implement if you are to do what you want to do.
      1. Determine the common part of the ID. In this case the current year.
      2. Form a filter such that only items matching this are included in the search.
      3. Find the maximum value so far used in the table that matches your criteria.
      4. Extract the sequential numeric portion of the value as a number. Remember to handle the case where none yet exists.
      5. Add 1 to the value from step #4.
      6. Take this number and format into the number of digits required.
      7. Concatenate the result after the Year.

      Comment

      Working...