Results 1 to 14 of 14
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Adding Leading Zeros

    I have a field that I need to be 5 characters. Access dropped the leading zero's when I imported the spreadsheet, and at the time I didn't think it was an issue, but now I realize it is. Is there a way that I can add the leading zero's into the field in my database?

  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
    A numeric data type can not hold the leading zeros, only a text data type can. You can get them with:

    Format(FieldName, "00000")

    either for display or as part of a process to update the field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I am an access beginner, where would I put that code in Access 2000 to make it display the leading "0"

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It looks like Paul might be getting some zzzzz's. Where do you want to display this numeric value with leading zeros?

  5. #5
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    i am wanting the leading 0's to be displayed on my form. my table does not show them either, so it makes sense for me to have to add them to the table first, then redesign the form. but how?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    As long as you just want to display the value and not alter it then Paul's suggestion in post #2 as the ControlSource of your control will work just fine. =Format([FieldName], "00000")
    This just alters how the field displays on this form and does not alter the field in the table.

  7. #7
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Where do I go to add the Control Source? That is what I am not understanding, I do not know where to input this code in order to make it display the leading zero's.

  8. #8
    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 enter that directly in the textbox in design view, or go into the textbox properties (double click on it) and enter it in the Control Source property on the Data tab.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    When I enter =Format([SKP B], "00000") in the Control Source, it displays as #Error

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Make sure the textbox doesn't have the same name as the field. That can confuse Access.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I have named the field SKP 2 and the Textbox remained named as SKP B, but it is still showing me #Error when I input =Format([SKP B], "00000") into the Control Source box.

  12. #12
    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 want the name of the field, not the textbox. Try

    =Format([SKP 2], "00000")

    The spaces in your names are not worth the bother in the long run.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    This may not matter, but do I need the text format set as plain text or rich text? It is set as plain text, but it isn't working set either way. Also, I have the field set as text.

    Now I receive the following error:

    #Name?

    I'm curious, why do you say the spaces in names are not worth it?

  14. #14
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I couldn't get this to work, by adding the code to the ControlSource, so I built a query and added this line into the SQL:

    =Format([SKP B], "00000")

    and it added my leading 0's

    All thanks for the help!

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

Similar Threads

  1. Chart report leading zeros
    By mulefeathers in forum Reports
    Replies: 9
    Last Post: 06-02-2010, 08:49 AM
  2. Replies: 6
    Last Post: 04-30-2010, 01:57 PM
  3. Replies: 9
    Last Post: 07-16-2009, 09:13 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