Results 1 to 5 of 5
  1. #1
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283

    IIf function

    Hello,

    I am trying to create an IIf function where it gets the length of the field. if it is under the length of 5 I want to add a "0" to the beginning of the field. I cannot get the query to work. It just deletes everything in the field.

    UPDATE Import_Template SET Import_Template.Zip_Code = IIf(Len([Zip_Code]>5),"0"+[Zip_Code],[Zip_Code]);




    I don't know what to put in as the false statement.

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Code:
     IIf(Len([Zip_Code])<5,"0"+[Zip_Code],[Zip_Code]);
    Change the parens this way. And change the GT to LT ( < )
    For zip_code to display the leading zero, it has to be a text field.
    Still a problem if the zip_code is less than 4 characters.
    You could run the query 4 times to take care of those lesser lengths.

  3. #3
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    It is a text field

  4. #4
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    Ahh nevermind got it to work thanks. It was the parenthesis..

  5. #5
    Join Date
    Apr 2017
    Posts
    1,679
    A general solution will be:

    a) If ZIP-code max length is 5 characters
    Right("00000" & ZipCode,5)
    b) If Zip-code max length can be longer than 5 characters, but not less than 5 charcters
    Iif(Len(ZipCode)>5, ZipCode, Right("00000" & ZipCode,5))

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

Similar Threads

  1. Replies: 15
    Last Post: 05-31-2017, 02:10 PM
  2. Replies: 2
    Last Post: 02-26-2017, 11:31 AM
  3. Replies: 3
    Last Post: 03-04-2016, 10:36 AM
  4. Replies: 8
    Last Post: 11-04-2014, 10:44 PM
  5. Replies: 8
    Last Post: 01-31-2014, 01:45 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