Results 1 to 7 of 7
  1. #1
    Ambre is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    11

    Select multiple rows from a table

    Hi,



    In my 'Family Tree' database I have a table (PersonTBL) that has columns PersonID (Autonumber), Mother ID (Long), FatherID (Long).
    Every person in the database has a record in this table. I want to build a query based on this table to show a person's family. This query will be called by a button on the PersonFRM.

    So, whatever person is being displayed on the PersonFRM the FamilyQRY should select from the PersonTBL: Mother (using MotherID), Father (using FatherID) and any children of these parents (using MotherID AND FatherID). If either of these parents re-marry it is important that the family only includes brothers/sisters from the same parents as indicated on the original PersonFRM.

    Sorry if this sounds very simple, but I am new to Access and cannot get a 'simple' query to to do this.

    Any assistance would be very much appreciated.

    Thanks,
    Ambre

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    You haven’t said what you want your result to look like but try this

    Join person table to itself (aliased as person_1) on mother and father ids

    set criteria on the person table to the person you want.

    you will need to join the aliased table to further aliased person table to get the parent and sibling names if that is what you require

  3. #3
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    232
    There are (at least) two issue here. First you need to find the proper criteria to select persons. Second is you want to show the role of a person. To solve this I think you need a UNION query. Something like (NOT tested):
    Code:
    SELECT *,  "Person" AS Role FROM PersonTBL WHERE PersonID = Forms!PersonFRM!PersonID
    UNION 
    SELECT *,  "Mother" AS Role FROM PersonTBL WHERE PersonID = Forms!PersonFRM!MotherID
    UNION 
    SELECT *, "Father" AS Role FROM PersonTBL WHERE PersonID = Forms!PersonFRM!FatherID
    UNION 
    SELECT *, "Brother/Sister" AS Role FROM PersonTBL WHERE MotherID = Forms!PersonFRM!MotherID AND FatherID = Forms!PersonFRM!FatherID AND PersonID <> Forms!PersonFRM!PersonID
    Groeten,

    Peter

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  5. #5
    Ambre is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    11
    Quote Originally Posted by Ambre View Post
    Hi,

    In my 'Family Tree' database I have a table (PersonTBL) that has columns PersonID (Autonumber), Mother ID (Long), FatherID (Long).
    Every person in the database has a record in this table. I want to build a query based on this table to show a person's family. This query will be called by a button on the PersonFRM.

    So, whatever person is being displayed on the PersonFRM the FamilyQRY should select from the PersonTBL: Mother (using MotherID), Father (using FatherID) and any children of these parents (using MotherID AND FatherID). If either of these parents re-marry it is important that the family only includes brothers/sisters from the same parents as indicated on the original PersonFRM.

    Sorry if this sounds very simple, but I am new to Access and cannot get a 'simple' query to to do this.

    Any assistance would be very much appreciated.

    Thanks,
    Ambre
    Many thanks for the reply.

    I did not know you could join a table to itself! Your suggestion has led me to a solution and INCREASED my knowledge and understanding of Access.

  6. #6
    Ambre is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    11
    Quote Originally Posted by xps35 View Post
    There are (at least) two issue here. First you need to find the proper criteria to select persons. Second is you want to show the role of a person. To solve this I think you need a UNION query. Something like (NOT tested):
    Code:
    SELECT *,  "Person" AS Role FROM PersonTBL WHERE PersonID = Forms!PersonFRM!PersonID
    UNION 
    SELECT *,  "Mother" AS Role FROM PersonTBL WHERE PersonID = Forms!PersonFRM!MotherID
    UNION 
    SELECT *, "Father" AS Role FROM PersonTBL WHERE PersonID = Forms!PersonFRM!FatherID
    UNION 
    SELECT *, "Brother/Sister" AS Role FROM PersonTBL WHERE MotherID = Forms!PersonFRM!MotherID AND FatherID = Forms!PersonFRM!FatherID AND PersonID <> Forms!PersonFRM!PersonID
    Many thanks for your reply.

    CJ_London's suggestion and yours has led me to a working solution.

  7. #7
    Ambre is offline Novice
    Windows 11 Office 365
    Join Date
    Apr 2023
    Posts
    11
    Quote Originally Posted by orange View Post
    You may get some additional ideas and insight for a genealogy database from this Richard Rost Youtube video.
    I will check this out. Thank you.

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

Similar Threads

  1. Select separate rows in table and write into Word File via Bookmarks
    By FinisherProgrammer21 in forum Programming
    Replies: 13
    Last Post: 01-26-2021, 10:20 AM
  2. Replies: 1
    Last Post: 09-01-2019, 06:01 AM
  3. Getting multiple rows into one row in select
    By rbevers in forum Queries
    Replies: 3
    Last Post: 08-30-2013, 01:58 PM
  4. Replies: 2
    Last Post: 09-18-2012, 06:20 AM
  5. Replies: 0
    Last Post: 11-30-2010, 12:51 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