Results 1 to 15 of 15
  1. #1
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25

    An update query except for certain things?

    Hello everyone! I have an update query that takes the values from Field1 in my table and populates them into Field2. The only problem is that I need to exclude any values that are "NA" or "TBD" from being copied over to Field2. I see where I can put positive criteria in the query, but not a negative. What is the best way to accomplish this?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    <>"NA" And <> "TBD"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    Quote Originally Posted by pbaldy View Post
    Try

    <>"NA" And <> "TBD"

    This didn't work for me, when I add this criteria in, it doesn't update anything

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Can you open query in SQL design mode and paste the SQL code for it? What pbaldy wrote should work for you.

  5. #5
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    This is what I have:


    UPDATE Table1 SET Table1.Field2 = Field1
    WHERE (((Table1.Field2)<>"NA" And (Table1.Field2)<>"TBD"));

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Oh, it seems you have criteria for the same column. In this case the OR operator is likely what you are after.
    WHERE (((Table1.Field2)<>"NA" OR (Table1.Field2)<>"TBD"));

  7. #7
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    Thank you!!!!!!!!!!!!!!!

  8. #8
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Did that work? I did small test and OR did not work. When using <> with 2 criteria you have to use AND. What am I missing?

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Bulzie View Post
    Did that work? I did small test and OR did not work. When using <> with 2 criteria you have to use AND. What am I missing?
    I did not test it or even give it much thought. I looked at the same field names and the AND. At that point a buzzer and a circle dash flashed in my view. Then I posted.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'll also be surprised if it works with Or. Nothing would be excluded from the update.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Quote Originally Posted by pbaldy View Post
    I'll also be surprised if it works with Or. Nothing would be excluded from the update.
    This. In my tests using OR updated all the records because those 2 conditions are exclusive if using <> with OR. Oh well if it works it works!!!

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Bulzie View Post
    ... Oh well if it works it works!!!
    Just because something happened, does not mean it works.

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    It seems the issue with post #5 is the fact there is not a value provided that will be used to process the UPDATE. In other words, a JOIN is missing or a parameter is missing.

    For example, this statement requires a JOIN on ID1
    Code:
    UPDATE TableTest1 INNER JOIN TableTest2 ON TableTest1.ID1 = TableTest2.ID1 SET TableTest2.Field2 = [TableTest1]![Field2]
    WHERE (((TableTest2.Field2)<>"NA" AND (TableTest2.Field2)<>"TBD"));

  14. #14
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    No both fields are in same table so no joins, just criteria to exclude records from the update.

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Bulzie View Post
    No both fields are in same table so no joins, just criteria to exclude records from the update.
    OK, I see that now.
    = Field1

    Not sure what caused the original issue then.

    .

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

Similar Threads

  1. Lining things up
    By Lou_Reed in forum Access
    Replies: 19
    Last Post: 08-20-2015, 11:33 AM
  2. Replies: 1
    Last Post: 01-25-2013, 10:34 AM
  3. Help on many things
    By scarruth2 in forum Access
    Replies: 11
    Last Post: 09-04-2012, 06:27 PM
  4. Replies: 1
    Last Post: 07-01-2012, 09:55 AM
  5. Replies: 10
    Last Post: 01-27-2012, 01:35 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