Results 1 to 9 of 9
  1. #1
    Fernando Access is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    5

    How to update field 1, 2 or 3, when they are null but leave as it is if they have information?

    Hello everyone,

    I'm trying to do an update query where I have, Field 1, Field 2, Field 3 and Field 4 if type says BTO as restriction.

    However, I only want Field 1, 2, 3 and 4 to be updated if any of them are blank, but if any of them has information, I don't want that to be updated and want to keep the original data.

    Is it possible to make it in a single query?

    Current query in image.



    Click image for larger version. 

Name:	Current Query.png 
Views:	21 
Size:	16.1 KB 
ID:	21987

    Thank you in advance!

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Instead of showing us something from an Access screen, why not tell us
    - an overview of the "business"
    -what you are trying to do in plain English
    - sounds like a logic/flow chart

    Code:
    if x and y and z then
     do something1
    else if XXX then
      do something2 
    ....
    else
     don't change anything
    end

  3. #3
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    >>I only want Field 1, 2, 3 and 4 to be updated if any of them are blank, but if any of them has information, I don't want that to be updated
    Wouldn't it be more accurate to say "
    I only want Field 1, 2, 3 and 4 to be updated if ALL of them are blank"
    If this is the case you want the "is null" for all 4 fields to be on the same row as the BTO

    Actually upon rereading your post again, I can't tell if you want no field updated if any of the 4 fields has info (see above), or if you don't want an individual field updated unless it is empty.

  4. #4
    Fernando Access is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    5
    Its component information for computers.

    My line record would look as the following:
    SKU: ABCDEFG#RRM, PROCESSOR_CHILD_PART_NUM: (blank), Processor Description: Intel i3 400GHZ, Processor Type: (blank), Processor Summary: Intel i3

    So what I want to tell the query is: if my Part# from tbl_File is equal to my Part# in tbl_Processor, update me only the labels that are null and leave alone the cells that already have information as they are, do this only when my SKU Type says BTO.

  5. #5
    Fernando Access is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    5
    Hi James: thanks for the reply,

    What I want is to update fields that are blank but if they have information I want them to leave it as it is, and only do this is my Part# of tbl_File is equal to Part# of tbl_Processor, where my SKU is "BTO".

    If my record is the following:
    SKU: ABCDEF#RRM, PROCESSOR_CHILD_PART_NUM: (blank), Processor Description: (blank), Processor Type: AMD, Processor Summary: AMD A-Series, SKU_Type: BTO
    Result: ABCDEF#RRM, PROCESSOR_CHILD_PART_NUM: HIJKLMOP#RMA, Processor Description: AMD A8 Quad Core, Processor Type: AMD, Processor Summary: AMD A-Series, SKU_Type: BTO

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    I am not sure which table is the source and which is the destination.

    Try this in the UPDATE TO row:

    Nz(DestinationTable.PROCESSOR_CHILD_PART_NUM, SourceTable.Processor_Child_Part_Num)

    or

    IIf(DestinationTable.PROCESSOR_CHILD_PART_NUM Is Null, SourceTable.Processor_Child_Part_Num, DestinationTable.Processor_Child_Part_Num)
    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.

  7. #7
    Fernando Access is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    5
    Quote Originally Posted by June7 View Post
    I am not sure which table is the source and which is the destination.

    Try this in the UPDATE TO row:

    Nz(DestinationTable.PROCESSOR_CHILD_PART_NUM, SourceTable.Processor_Child_Part_Num)

    or

    IIf(DestinationTable.PROCESSOR_CHILD_PART_NUM Is Null, SourceTable.Processor_Child_Part_Num, DestinationTable.Processor_Child_Part_Num)
    Thank you for the answer June, this is for PROCESSOR_CHILD_PART_NUM, if I have 2 other labels such as Processor Type and Processor Summary, do I need to create one query for each label or is it possible to do it in a single code? Keeping in mind that I only want those null values to be updated when my SKU_Type is "BTO".

    Regards,
    Fernando

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Can update as many fields as you want in a single SQL action.

    If you want to restrict records that are impacted by the UPDATE, apply filter criteria to the SKU_Type field.
    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.

  9. #9
    Fernando Access is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    5
    June, thank you this is exactly what I was looking for.

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

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2015, 11:08 AM
  2. Leave Single Character Field when Entered
    By EddieN1 in forum Forms
    Replies: 4
    Last Post: 08-30-2013, 01:02 PM
  3. Update query to set null value lookup field
    By alexjose in forum Access
    Replies: 1
    Last Post: 06-24-2013, 04:26 PM
  4. Check for required when leave the field
    By Rhubie in forum Forms
    Replies: 13
    Last Post: 09-12-2012, 02:17 PM
  5. Update field1 if Null, if Not Null update field2
    By mfirestorm in forum Queries
    Replies: 2
    Last Post: 12-02-2011, 09:51 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