Results 1 to 7 of 7
  1. #1
    tylerpickering is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    22

    Changing table values based on IF statement

    Hi guys--

    Total Access newb here, I have a database that has an "Origin Country" field and need to standardize the names...ex. Canada needs to be CAN, but are currently CA and CN.



    Here is what I came up with so far:

    Code:
    OCountry: IIf([Origin Country]="CA","CAN",iif([Origin Country]="CN","CAN",iif([Origin Country]="MX", "MEX",iif([Origin Country]="ME", "MEX",[Origin Country])))
    However, it does not create the new country code as I had hope. Not sure if OR statements are possible like in excel (obviously making this much simpler), but like I said, big time n00b hoping to learn.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I think the easiest thing to do would be to create a lookup table of all your different countries, and simply link your table to it and return the right value, i.e.
    Code:
    LookupValue   ValueToReturn
    CA                CAN
    CAN               CAN
    CN                CAN
    ME                MEX
    MEX               MEX
    MX                MEX
    So, you would just do a Left Join from your main data table on the to this table, joining on the LookupValue field, and returning the ValueToReturn field.

    The beauty of this is you can easily add other countries and/or abbreviations to this data table in the future (as the need arises), and not have to change any of your formulas in your queries!

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Yes, lookup table is best, especially if you have a lot of countries and/or want to allow adding countries.

    However, don't understand "it does not create the new country code". The expression should work. If you want to actually change the value in the field, that requires an UPDATE action SQL.

    Don't you want to use the international 2-letter code for addressing? Or there is a 3-letter standard http://www.unc.edu/~rowlett/units/codes/country.htm
    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.

  4. #4
    tylerpickering is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    22
    Thanks to you both for responding! I'll create a table and see how it goes--thanks again!

  5. #5
    tylerpickering is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    22
    So, I'm not sure how to do this join...could you help me out with the query language?

    Here's what I have

    Origin Fixed: : FROM [Country Codes] Left JOIN [All Columns] ON [All Columns].[Origin Country] to [Country Codes].ValueToReturn
    Last edited by tylerpickering; 04-01-2014 at 10:39 AM. Reason: Forgot code

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Easiest way is to add both tables to Query View, drag a line from the "Origin Country" code field in the main table to the matching field in your lookup table.
    Then, double-click the line you just made by joining this two fields and select the second radio button option listed there.

    Then, simply select the fields you want to return from the tables.

  7. #7
    tylerpickering is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    22
    Ah got it, much easier...thanks!

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

Similar Threads

  1. Replies: 6
    Last Post: 11-22-2013, 07:59 PM
  2. Replies: 2
    Last Post: 11-12-2012, 03:52 AM
  3. Replies: 3
    Last Post: 01-16-2012, 02:34 PM
  4. Master list table with changing values.
    By evander in forum Database Design
    Replies: 11
    Last Post: 06-24-2010, 07:40 AM
  5. update table in loop based on IF statement
    By LALouw in forum Access
    Replies: 0
    Last Post: 07-26-2009, 08:46 PM

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