Results 1 to 4 of 4
  1. #1
    avegrrl is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    2

    Question Expression drops leading zeros - how can I prevent this?

    I have a fixed-width text file that I import daily and split into a bunch of fields. For two pairs of fields, I concatenate the values to create a dollar amount. E.g. | 123 | 45| becomes $123.45. For one (and only one) pair of fields, the second entry is dropping any leading zeros. So instead of $123.01, the query is resulting in a value of $123.1, which reformats to $123.10.

    The one that IS working has the dollar field set as a number and the Cents field set as text with two digits. Modeling the broken one after that doesn't work. I can get the table to display correctly by setting both fields to Numbers with a format of 00 for cents, but the results of the query are still wrong.



    The query is: Expr1: [Dollars] & "." & [Cents]

    Any ideas? Sorry if that was a convoluted question.

  2. #2
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254
    avegrrl -

    Don't know if this will help but, you could try...

    Adding a new expression field to the query, like...

    ACents: IIF(Len([Cents])=1, "0" & [Cents],[Cents])

    and then reference that expression in the other expession...

    Expr1: [Dollars] & "." & [ACents]

    Untested but, may be worth a try.

    All the best,

    Jim

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What you describe makes sense. When Access (or Excel) imports a string into a number field, both programs will drop leading zeros because they "think" the value shoud be a number, not text.


    Jim's solution should work. You could also combine the two columns into one column in the query:

    Expr1: [Dollars] & "." & IIF(Len([Cents])=1, "0" & [Cents],[Cents])



    I would probably import the dollars and cents data as text. Then the original expression would work with no changes:

    Expr1: [Dollars] & "." & [Cents]


    IF you needed to change the string to a number, you could use:

    Expr1: CCur([Dollars] & "." & [Cents])


    Many ways to skin a cat...

  4. #4
    avegrrl is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    2
    Thank you both. Adding the IIF to the Expression worked perfectly!

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

Similar Threads

  1. Trying to get leading zeros to show
    By Pegasus_Angel in forum Access
    Replies: 3
    Last Post: 10-25-2012, 11:40 AM
  2. Replies: 4
    Last Post: 10-06-2012, 10:25 AM
  3. Leading Zeros
    By dirtbiker1824 in forum Access
    Replies: 1
    Last Post: 03-14-2011, 02:16 PM
  4. Adding Leading Zeros
    By jo15765 in forum Access
    Replies: 13
    Last Post: 11-20-2010, 11:11 PM
  5. leading 'Zeros' in data
    By wasim_sono in forum Forms
    Replies: 3
    Last Post: 04-06-2009, 11:57 AM

Tags for this Thread

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