Results 1 to 4 of 4
  1. #1
    ADFC is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Apr 2014
    Posts
    4

    How to create an ID with the current year on it

    Hello.

    How can I create a table with an ID Primary Key with the current year on it?

    The format I was looking for could be something like:
    14-000

    That way when creating a new record the ID field should automatically populate itself with the following:
    14-001
    14-002
    14-003
    etc...

    And in 2015 it should automatically populate itself with the following:
    15-001
    15-002
    15-003
    etc...



    Thanks

  2. #2
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    Bad idea, if it can be done like that at all. what you need to do is add another pk based on the main pk and date

    eg tbl2_pk = tbl1_pk & format(date(),"yy") add the current year to the pk of the table and adds a new pk field.
    never needed to do that, so you will need extra advice on how to add this

    1000 ways to skin a cat, allways looking for another one...
    Use MDB format for sample post. If your issue is fixed, mark the thread solved.
    Click on the star below if this has helped.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I would try to fight the business rules and concatenate the year to an autonumber field.

    I doubt it would be impossible to start a new series each calendar year. I can imagine a couple of solutions. It would be a little bit of code and a pain to develop the app at future dates because you have to consider said series convention.

    I suggest concatenate or use the Format property of an Autonumber field at the table level.

    >format(date(),"yy")

    as a format should display the year and not disrupt the underlying value of the field.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 06-21-2013, 07:18 AM
  2. Current Month/Year Query
    By Roadbeer in forum Queries
    Replies: 3
    Last Post: 06-17-2013, 01:20 PM
  3. checking if current year
    By snoopy in forum Queries
    Replies: 2
    Last Post: 06-20-2012, 01:46 AM
  4. Replies: 1
    Last Post: 11-05-2010, 05:49 PM
  5. Changing a date to the current year
    By fdnyfish in forum Access
    Replies: 1
    Last Post: 03-01-2008, 08:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums