Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2022
    Posts
    11

    Adding a leading zero(0) to field


    Hi All,

    I have a field that contains a social security number. If only the last 4 digits are provided, I fill the leading spaces with zeros manually. However, is there a 'simple' way, perhaps with a little code, to have those leading spaces automatically filled in with zeros so I do not have to type them in manually.

    Thanks for your help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Assume this is a text type field.

    Yes, code can add leading zeros to value when committed to table.

    Or format field to only display additional zeros when needed. This may be the simpler approach.

    Format([SSN],"000-00-0000")


    Review:
    https://stackoverflow.com/questions/...0for%20display.

    Storing Social Security Numbers and Credit Card Information (microsoft.com)
    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.

  3. #3
    Join Date
    Nov 2022
    Posts
    11
    Perfect that makes sense thank you!

  4. #4
    Join Date
    Nov 2022
    Posts
    11
    This may sound stupid, but this totally worked yesterday but for some reason now in the format property the it is showing up like this : "For"m"at(["ssn"],000-00-0000)

    Am I missing anything?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Can't use in Format property. This would be an expression used in a query or textbox.

    Might be able to use Format property but then would not use Format() function.


    I do not have Access available now to test.
    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.

  6. #6
    Join Date
    Nov 2022
    Posts
    11
    If using the format property, would it just be 000000000 or something else? I have an input mask that places the dashes (000-00-0000) when typing in a social. Thanks!

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I think InputMask overrides Format.
    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: 3
    Last Post: 07-01-2016, 08:11 AM
  2. Replies: 3
    Last Post: 07-08-2015, 07:18 PM
  3. Replies: 1
    Last Post: 03-17-2015, 05:27 PM
  4. Adding leading spaces to a field
    By johnbr in forum Queries
    Replies: 1
    Last Post: 12-13-2011, 11:31 AM
  5. Adding Leading Zeros
    By jo15765 in forum Access
    Replies: 13
    Last Post: 11-20-2010, 11:11 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