Results 1 to 7 of 7
  1. #1
    catguy is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2010
    Location
    Minnesota
    Posts
    20

    How to add leading zeros for 12 char length

    I have 2 tables, each with a field named "Lots", which are text data types.
    The problem I have, is that the data for each table comes from a different data source, each using the same "lot number", except the character length from table 1 varies from 8 characters to 10 characters, depending on the number, and the character length in table 2 is a consistent 12 characters. (i.e. table 1: 100000325 and table 2: 000010000325)
    In table 2, there are "leading zeros" added to the number to make it 12 characters in length.
    Unfortunately, the data source adds these automatically to one of the data dumps, but I cannot change it to do this for the other data dump, so I need to do it in access.
    How can I add leading zeros to the "Lots" field in table 1 so that it matches the 12 characters of table 2?
    It can't be that difficult, but I'm at a loss......Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use the Format() function:

    Format(FieldName, "000000000000")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    catguy is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2010
    Location
    Minnesota
    Posts
    20
    Thanks Baldy, but I tried that earlier. It only returns those records that already contain 12 characters, and of the 3,768 records, only 370 of them have the full 12 chars.
    Any other thoughts?
    I need to add enough zeros to the existing number to bring up to 12 chars. ("100000325" [8 chars] or "890000016" [9 chars] needs to be changed to "000010000325" or "000890000016")

  4. #4
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Try This:
    String(12-(Len([Lots])),"0") & [Lots]
    This will add sufficient no.of.zeros to make all the records have 12 characters.
    if this solves your problem mark this thread solved.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That is a commonly used method to pad zeros. It sounds like you may have used it as a criteria instead of a field.

    Quote Originally Posted by catguy View Post
    Thanks Baldy, but I tried that earlier. It only returns those records that already contain 12 characters, and of the 3,768 records, only 370 of them have the full 12 chars.
    Any other thoughts?
    I need to add enough zeros to the existing number to bring up to 12 chars. ("100000325" [8 chars] or "890000016" [9 chars] needs to be changed to "000010000325" or "000890000016")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    catguy is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2010
    Location
    Minnesota
    Posts
    20
    Quote Originally Posted by pbaldy View Post
    That is a commonly used method to pad zeros. It sounds like you may have used it as a criteria instead of a field.
    You are absolutely correct...... and after I got over my Homer Simpson "DOH", I realized that I had tried using it the criteria.
    Using it the field worked just as it should. It's been a long, long week.... Thanks

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problemo; we all have our "DOH" moments. Though I seem to have more than my fair share.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. 8000 char max for memo?
    By okerix in forum Access
    Replies: 0
    Last Post: 04-29-2010, 08:55 AM
  2. Replies: 1
    Last Post: 03-09-2010, 10:23 AM
  3. Replies: 1
    Last Post: 06-01-2009, 04:05 PM
  4. leading 'Zeros' in data
    By wasim_sono in forum Forms
    Replies: 3
    Last Post: 04-06-2009, 11:57 AM
  5. Leading Zeroes
    By FREEEEEEDOM in forum Access
    Replies: 2
    Last Post: 04-06-2009, 10:23 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