Results 1 to 4 of 4
  1. #1
    cver22 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    2

    Job number formatted with 2 digit year and leading zeros

    Hey there,

    I've searched everywhere and can't seem to sort this out. I'm looking to have our job numbers auto numbered with a two-digit year out front:

    YY######

    The first job number created would be (as this is 2017 right now):

    17000001

    Next year we'd be happy to continue with the same numbering so let's assume we've done 87 jobs and this would be our first one in 2018:



    18000088

    I've tried creating it all using autonumbering but it doesn't like taking the date. So instead I've just left autonumbering on its own, created a date Field Name and then tried to calculate them together in "Project_Number" field

    This is the code I've managed to concoct, however, the data output deletes a bunch of zeros and adds spaces for no reason:

    Str(Right(Year([Date_Created]),2)) & Right(Str("000000") & Str([ID]),6)

    The example above would come out to:

    18 0 88

    Any thoughts would be greatly appreciated.

    Cheers!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    In a query you could use a calculated field. Something like:
    Code:
    Result:Right([YourDateField],2) & Format([YourAutoNumField],"000000")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You shouldn't have the STR() function around the string of zeros. Try:
    Code:
    Str(Right(Year([Date_Created]), 2)) & Right("000000" & CStr([ID]), 6)
    I create a sub with two variables to mimic your fields... the string "17000088" was returned.



    <snip> created a date Field Name and then tried to calculate them together in "Project_Number" field
    Did you really create a date field to store a string????

  4. #4
    cver22 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    2
    Quote Originally Posted by ssanfu View Post
    You shouldn't have the STR() function around the string of zeros. Try:
    Code:
    Str(Right(Year([Date_Created]), 2)) & Right("000000" & CStr([ID]), 6)
    I create a sub with two variables to mimic your fields... the string "17000088" was returned.




    Did you really create a date field to store a string????

    Taking the Str off it worked beautifully, thanks!

    Yes, I need both the date and the job number for different purposes and couldn't figure out how to make it work. I've done a bit of Java, but I'm very new to access.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-11-2015, 05:35 PM
  2. Do not add leading zeros
    By phifer2088 in forum Access
    Replies: 5
    Last Post: 03-02-2015, 10:05 AM
  3. matching number with leading zeros
    By webisti in forum Access
    Replies: 1
    Last Post: 01-28-2015, 06:47 AM
  4. Trying to get leading zeros to show
    By Pegasus_Angel in forum Access
    Replies: 3
    Last Post: 10-25-2012, 11:40 AM
  5. Leading Zeros
    By dirtbiker1824 in forum Access
    Replies: 1
    Last Post: 03-14-2011, 02:16 PM

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