Results 1 to 8 of 8
  1. #1
    gh05 is offline Novice
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    5

    Updating a yes/no column where data exists for that ID in another table?

    I have two tables, both have a common ID field.

    One table (the one that I want to update) has a yes/no field and I want it to say 'yes' if a record exists for that ID in the other table. If no record exists for that ID in the other table then it should say 'no'.

    I'm guessin this should be simple but don't now how.



    Any help much appreciated

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    What have you tried? What error did you get?

  3. #3
    gh05 is offline Novice
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    5
    Quote Originally Posted by orange View Post
    What have you tried? What error did you get?
    I haven't yet - If the table which I want to use to update the main table had yes/no in it as a column then I would just create a query to pull the two together where the ID is the same but because this second table only contains those which are 'yes' then I'm not sure of what to do.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    From a logical perspective, consider this.

    Lets say TblA is the table with the Yes/No field (I 'll call it Chk, and in this example it is a Yes/No field (Boolean))
    and your second table is TblB. TblA and TblB both have a field called Id.

    TblA.Chk will be True/Yes if the Id is in TblB
    TblA.Chk will be No/False if the Id is not in TblB

    So,you know how to set the field to Yes/True where the Id is equal.

    Well what if you first set all the Chk fields to NO/False,
    then run the query you already know, to set the Chk to Yes/Ture where the Ids are equal.

    That way you get the result you want.




    The query you already know is

    UPDATE TablA INNER JOIN TablB
    ON TablA.id = TablB.id
    SET TablA.Chk = True
    So, the query you need to set all the values of Chk to No/False is

    Update TblA
    Set Chk = False
    Make sense?

  5. #5
    gh05 is offline Novice
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    5
    Quote Originally Posted by orange View Post
    From a logical perspective, consider this.

    Lets say TblA is the table with the Yes/No field (I 'll call it Chk, and in this example it is a Yes/No field (Boolean))
    and your second table is TblB. TblA and TblB both have a field called Id.

    TblA.Chk will be True/Yes if the Id is in TblB
    TblA.Chk will be No/False if the Id is not in TblB

    So,you know how to set the field to Yes/True where the Id is equal.

    Well what if you first set all the Chk fields to NO/False,
    then run the query you already know, to set the Chk to Yes/Ture where the Ids are equal.

    That way you get the result you want.




    The query you already know is



    So, the query you need to set all the values of Chk to No/False is



    Make sense?
    Hi,

    Thanks, yes the logic makes sense. I just wasn't sure how to do the query - so is this just a basic update query then? How do you 'set' the checkboxes without using the sql code?

    thanks

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    The sql code is what lies behind the Access Query Wizard (interface).

    You should be familiar with the Query Wizard. You have probably used it for Select queries. If not, you should get familiar with it.

    Also, you should be cautious when using Update queries. If the proper constraints are not used properly, you could modify ALL records, or the UNINTENDED records.

    see http://www.techonthenet.com/sql/update.php

  7. #7
    Rhino373 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    65
    To set it, in the update query, you'll use 0 for No and 1 for Yes. Set the criteria to 1 to change the field to Yes

  8. #8
    gh05 is offline Novice
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    5
    thanks both. sorted now.

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

Similar Threads

  1. Updating table data while in use
    By crispy-bacon in forum Access
    Replies: 5
    Last Post: 06-03-2011, 12:49 PM
  2. Updating table's column via VBA
    By Amerigo in forum Programming
    Replies: 10
    Last Post: 03-24-2011, 10:07 AM
  3. Replies: 1
    Last Post: 11-05-2010, 04:51 AM
  4. Updating Table Data Automatically
    By aquarius in forum Import/Export Data
    Replies: 6
    Last Post: 09-16-2010, 03:07 PM
  5. Updating data within a form/table.....
    By softspoken in forum Forms
    Replies: 3
    Last Post: 04-15-2010, 06:33 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