Results 1 to 5 of 5
  1. #1
    Muffel2k is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    5

    Hide specific query results by subtable


    Hi,

    I would like to create a query to gather records from a table by excluding some based on a subtable.


    First table (which returns the query results)
    Field 1 ID_Projekte
    Field 2 Projektname
    Field 3 Bezeichnung
    Field 4 Bemerkung

    The query to return all the projects is simple but now I would like to remove some of the results based on a second table looking like this:

    Second table (additonal information for each project)
    Field 1 ID_Projektphase
    Field 2 ID_Projekte_FK
    Field 3 ID_ProjektphasenID
    Field 4 Bezeichung

    "Field 1" from the first table is linked to "Field 2" from the second table with a 1:many relationship (which means each project from the first table can have multiple entries on the second table. The difference is "Field 3" on the second table which is an indicator for a specific process. This field contains a number between 1 and 20 and there can be up to 10 records for each project). What I want to do is to show all Projects which do not have a value of "4" or "10" in "Field 3" on the second table. If I just add an additional criteria to my query it still shows the project as there are entries with "ID_ProjektphasenID" = 1 (or another value) but I need to hide the project completely if there is an entry with 4 or 10.

    right now my SQL query Looks like this:
    Code:
    SELECT DISTINCT tbl_Projekte.ID_Projekte, tbl_Projekte.Projektname, tbl_Werkzeugtypen.Bezeichnung, tbl_Projekte.Werkzeugnummer, tbl_Projekte.Projekttyp, tbl_Projekte.Bemerkung
    FROM tbl_Werkzeugtypen INNER JOIN (tbl_Projekte INNER JOIN tbl_Projekte_Phasen ON tbl_Projekte.ID_Projekte = tbl_Projekte_Phasen.ID_Projekte_FK) ON tbl_Werkzeugtypen.ID_Werkzeugtypen = tbl_Projekte.Werkzeugtyp
    WHERE (((tbl_Projekte.Projekttyp)=[Formulare]![frm_Kundenauftraege]![Projekttyp]) AND ((tbl_Projekte_Phasen.ID_Projektphasen_FK)<>4))
    ORDER BY tbl_Projekte.Projektname DESC;
    and here is a screenshot of my Project
    Click image for larger version. 

Name:	Unbenannt.JPG 
Views:	11 
Size:	82.8 KB 
ID:	30961

    the table in the middle is "Table 1" and the right one is "Table 2".
    Any ideas what I can do?
    Last edited by Muffel2k; 10-28-2017 at 01:36 AM.

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Replace the table with a query that excludes 4 and 10 from the start, then use that query in your joins above. Or you can insert the query above into a new query, add all the fields then filter in criteria for <> 4 and <> 10, etc.

  3. #3
    Muffel2k is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    5
    I think I've got your point but how do you manage to exclude the whole project? Let's say I have these projects created on table 1:

    Test 1
    Test 2
    Test 3


    on table 2 there are several entries for these projects. As example:

    Test 1: ID_ProjektphasenID = 1
    Test 1: ID_ProjektphasenID = 3
    Test 1: ID_ProjektphasenID = 4
    Test 2: ID_ProjektphasenID = 9
    Test 2: ID_ProjektphasenID = 11
    Test 3: ID_ProjektphasenID = 10


    My query returns all of them and with the criteria I still get "Test 1" and "Test 2". "Test 3" is removed due to the criteria but "Test 1" is still there because there are entries with different values than 4 and 10.
    "Test 1" should be removed as well. Not sure how to do that.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Create a query of all projects that have a 4 or a 10. Then exclude those in your next query (left join with project=Null).

  5. #5
    Muffel2k is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    5
    worked like a charm, thank you!

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

Similar Threads

  1. Replies: 1
    Last Post: 02-23-2016, 08:36 PM
  2. 'SubTable' to manage items attached to a specific record
    By RichardGR in forum Database Design
    Replies: 4
    Last Post: 04-03-2013, 02:37 AM
  3. Replies: 1
    Last Post: 09-24-2012, 07:09 PM
  4. Hide Subreport if specific fields are empty
    By hawkins in forum Reports
    Replies: 1
    Last Post: 03-29-2012, 05:08 PM
  5. How do I subtable?
    By blippy in forum Database Design
    Replies: 7
    Last Post: 07-21-2011, 10:49 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