Results 1 to 9 of 9
  1. #1
    rockell333 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    33

    Update Multiple fields with multiple criteria

    I have 3 different fields I am trying to update.
    The first two are below - type and description.

    based on the deliverability code I need the description and address to be different things. I havent listed them all here. What am I doing wrong?




    UPDATE [Copy Of NIXIES]


    SET
    OLD_Related_Address_Type = "Old Address", OLD_Related_Address_Description = "Moved No Forwarding Address"
    WHERE
    DELIVERABILITY_CODE = 'K'
    OLD_Related_Address_Type = "Bad Address", OLD_Related_Address_Description = "Attempted, Not Known"
    WHERE
    DELIVERABILITY_CODE = 'A';

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You cannot do it like that. First, you cannot have multiple WHERE clauses like that. The word "WHERE" should only show up once in a query, unless you have a subquery.

    If instead of making three different simple UPDATE queries (one for each set of criteria),you want to try to do it in a single query, take a look at this thread here:
    http://www.pcreview.co.uk/threads/ca...query.1174562/

    If you have issues getting it to work, post back.

  3. #3
    rockell333 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    33
    ok.. i get that.. Now can i set two fields based on the same criteria?

  4. #4
    rockell333 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    33
    Not Working ???

    UPDATE Copy_Of_NIXIES
    SET [OLD_Related_Address_Type] =
    SWITCH
    (DELIVERABILITY_CODE LIKE 'K',"Old Address",
    DELIVERABILITY_CODE LIKE 'A',"Bad Address",
    DELIVERABILITY_CODE LIKE 'Q',"Bad Address",
    DELIVERABILITY_CODE LIKE 'I',"Bad Address",
    DELIVERABILITY_CODE LIKE 'V'),"Bad Address","Nothing"
    )

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    ok.. i get that.. Now can i set two fields based on the same criteria?
    Yes, you can update multiple fields, just separate them with a comma.

    So your structure would look like:

    Code:
    UPDATE [TableName]
    SET [Field1]=..., [Field2]=...
    WHERE [Field3]=...
    If you had multiple fields in your Criteria, you would just use AND or OR.

  6. #6
    rockell333 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    33
    the "field 1" and "field 2" are different based on criteria... meaning

    if the del code is k field 1 is old and field 2 vacant
    if del code is Q field one is bad and field to is refused
    if del code is S field one is bad and field to is bad number

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    OK, here is a better way to go about it.

    Make a lookup table, with two fields: DELIVERABILITY_CODE and OLD_Related_Address_Type.
    Then populate this table with each possible DELIVERABILITY_CODE and the corresponding OLD_Related_Address_Type you want to return.
    Then, link this Lookup table your main table, and use it in the Update Query, i.e.
    Code:
    UPDATE Copy_of_NIXIES 
    INNER JOIN Lookup_Table 
    ON Copy_of_NIXIES.DELIVERABILITY_CODE = Lookup_Table.DELIVERABILITY_CODE 
    SET Copy_of_NIXIES.OLD_Related_Address_Type = [Lookup_Table]![OLD_Related_Address_Type];

  8. #8
    rockell333 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    33
    ahhh.. that makes sense. I will try that now

  9. #9
    rockell333 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    33
    PERFECT... thank you...

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

Similar Threads

  1. Replies: 3
    Last Post: 10-08-2014, 10:28 AM
  2. update query with multiple criteria help
    By mbellas21 in forum Queries
    Replies: 2
    Last Post: 06-12-2013, 02:27 AM
  3. Replies: 5
    Last Post: 04-05-2013, 12:02 PM
  4. FindFirst with multiple fields in criteria
    By compooper in forum Programming
    Replies: 5
    Last Post: 07-22-2011, 10:29 AM
  5. Update Multiple fields according multiple criterias
    By denis.m in forum Programming
    Replies: 1
    Last Post: 02-21-2011, 11:03 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