Results 1 to 3 of 3
  1. #1
    Slush is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    38

    format zipcode in form

    I need to format zip codes in a form as either 5 characters or 9 characters with a dash. The data in the field do not contain dashes. I have tried the following code in the unbound control source of the form, but neither work.

    =IIf(Len([Zip])>=6, Left([Zip],5) & "-" & Right([Zip],4),[Zip])




    =IIF(Len(zip)=6, Left(zip,5),IIF(Len(zip)=9,Format(Zip,"@@@@@-@@@@"),Zip))

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    When you say neither one works, what do you mean? Is anything displayed, and if so what does it look like? I don't see anything wrong with the expressions, especially the first one.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by Slush View Post
    ...I have tried the following code in the unbound control source of the form, but neither work...
    First off, Forms don't have Control Sources...Controls have Control Sources!

    Are you saying that you're using the first expression in the Control Source of an unbound Control? Or are you trying it in the Control Source of the Zip Textbox? If the former, it should work, assuming that the Control Name is actually Zip, and not something like txtZip.

    The second expression won't work, in the Control Source, because Zip would need to have Square Brackets around it (as in your first example) when used like this in a Control Source.

    Linq ;0)>

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

Similar Threads

  1. Replies: 0
    Last Post: 11-19-2014, 05:47 AM
  2. Add Leading 0 to a Zipcode
    By tylerpickering in forum Queries
    Replies: 8
    Last Post: 04-01-2014, 12:22 PM
  3. Replies: 4
    Last Post: 03-12-2013, 06:49 PM
  4. Zipcode Lookup Autofill
    By jgalloway in forum Access
    Replies: 25
    Last Post: 09-20-2011, 06:54 PM
  5. Looking up a zipcode
    By rbw95662 in forum Forms
    Replies: 1
    Last Post: 03-24-2010, 05:07 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