Results 1 to 3 of 3
  1. #1
    EmilyMoon is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    1

    Question Update Yes/No field over one to many relationship

    Hi,

    I have a database with two tables joined by a one to many relationship ("Master" to "Nested"). I have a yes/no column in each table.


    I would like to use an update query to update yes/no records in the master table using yes/no records in the nested table. However as there are multiple records in the nested table, the method I'm currently using only updates the master table based on the last listed yes/no result in the nested table for each record.

    What I would like it to do is to update the master table yes/no column to yes if ANY of the associated nested table records are yes...

    Any advice greatly appreciated

    Emily

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    UPDATE testN INNER JOIN testM ON testN.keyfield = testM.keyfield SET testM.[yesno] = True
    WHERE (((testN.check)=True));

    (testN is the nested table, testM is the master)

  3. #3
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    If you base your decision on the child records why bother updating the parent record at all? There would be no need to do that. You can just query the child records and if there is at least 1 yes then you know the status of the parent record.

    Not knowing your table structure it is hard to give you specifics but if it looks something like this...

    tblParent
    -pkParentID primary key, autonumber

    tblChild
    -pkChildID primary key, autonumber
    -fkParentID foreign key to tblParent
    -youryesnofield

    ...then you will need a series of queries to get the information you need.

    This first query returns all the records that have yes responses

    query name: qryYesResponsesbyfkParentID
    SELECT tblChild.fkParentID, tblChild.youryesnofield
    FROM tblChild
    WHERE (((tblChild.youryesnofield)=True));

    We can modify the above query to return 1 record for each fkParentID with a yes by adding DISTINCT to the SELECT clause.

    SELECT DISTINCT tblChild.fkParentID, tblChild.youryesnofield
    FROM tblChild
    WHERE (((tblChild.youryesnofield)=True));


    The above query will now tell us which parents had at least 1 yes and there is no need to even have the yes/no field in the parent table.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-31-2011, 04:03 PM
  2. Update field in subform from field in Main
    By jpkeller55 in forum Access
    Replies: 9
    Last Post: 10-15-2010, 03:37 PM
  3. Update field in table after update on a subform
    By jpkeller55 in forum Queries
    Replies: 3
    Last Post: 09-30-2010, 08:02 PM
  4. Replies: 2
    Last Post: 05-05-2010, 02:52 PM
  5. one to many relationship and field adding
    By cr1973 in forum Queries
    Replies: 0
    Last Post: 08-27-2009, 07:12 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