Results 1 to 7 of 7
  1. #1
    halt4814 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    19

    Report shows 16 records when only supposed to show 1


    Hi all,

    I have a report that when displayed should show information from various forms. On my report design I have 3 subforms, which the report is pulling data from.

    The strange part is that each record displayed in the report shows the same information over and over 16 total times. I was thinking it was some kind of grouping error, but I do not know how to go about fixing this issue. Any ideas?

  2. #2
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Usually, this will be the result of a query that is improperly joined, something called a cross-join.

    Suppose you have two tables: T1 has 12 records in it and T2 has 16 records in it.

    If you have a query that looks like this:
    Code:
    SELECT T1.field1, T2.Field2
    FROM T1, T2
    WHERE T1.field1 = "george";
    Then you're going to get 16 records that all say "george" - 1 for each record in T2.

    The proper query will look more like this
    Code:
    SELECT T1.field1, T2.Field2
    FROM T1, T2
    WHERE T1.field1 = "george"
    AND T1.Matchfield = T2.MatchField;
    Or the same query also might look like this
    Code:
    SELECT T1.field1, T2.Field2
    FROM T1 
            INNER JOIN T2
            ON T1.Matchfield = T2.MatchField
    WHERE T1.field1 = "george";

  3. #3
    halt4814 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    19
    This is my query that the report is based off...

    SELECT PLANT_AREAS.PA_NAME, PLANT_AREAS.ASSOC_ROOM_LIST, PLANT_AREAS.PA_DESCR, FIXED.FC_HEATCONTENT, TRANSIENT.TC_HEATCONTENT, CABLE_TRAYS.CT_HC, PLANT_AREAS.FLOOR_AREA, PLANT_AREAS.PA_COMMENT
    FROM ((PLANT_AREAS INNER JOIN FIXED ON PLANT_AREAS.[PA_NAME] = FIXED.[PA_NAME]) INNER JOIN TRANSIENT ON PLANT_AREAS.[PA_NAME] = TRANSIENT.[PA_NAME]) INNER JOIN CABLE_TRAYS ON PLANT_AREAS.[PA_NAME] = CABLE_TRAYS.[PA_NAME]
    WHERE (((PLANT_AREAS.PA_NAME) Like [Forms]![Combustible Summary Report Parameters]![Combo45]));


    So, I have some INNER JOIN's in there, but it still displays 16 records when I only want one....

  4. #4
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Okay, so (1) check each table and make sure that [PA_NAME] is a unique key, duplicates not allowed.

    (2) something looks squirrelly about the join, given the names.

    I'm assuming that PA_NAME is the name of a area in the plant, and that Fixed is a one-to-many list of (Items of Some Sort) that are in fixed areas of the plant, while TRANSIENT is a one-to-many list of (Items of Some Sort) that moves from place to place in the plant as needed. If that's true, then it's nonsensical to ever join FIXED to TRANSIENT. I'd expect a similar design error with CABLE_TRAYS.

    THE only way your join makes sense is if there is only ever one Fixed, one Transient, and one CableTray for each area of the plant. Is that the actual business situation?

  5. #5
    halt4814 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    19
    Ok so I took out the INNER JOINs, and it worked. Only one record is displayed, however now the table fields that I had in the header section are blank. Nothing is populating in those fields now.

  6. #6
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    Recoded SQL

    If you explain what each of those tables actually mean, and which of them can have duplicates, I can tell you what I'd do to display them. I think I've worked it out, but you can tell me if I'm wrong.

    It's likely, given the field names, that you are trying to display the total heat load. That's the "SUM" in each section below. That calculation will give you the sum of all the heat content records of each type, if any records of that heat category type exist for that Plant Area, or return zero if none exist.

    You could also switch each SUM to MAX (or MIN, or AVG) in the code below will give you the single record of each type with the largest (or smallest, or average) heat content, if any records of that heat category type exist for that Plant Area, or return zero if none exist.
    Code:
    SELECT 
       tPA.PA_NAME, 
       tPA.ASSOC_ROOM_LIST, 
       tPA.PA_DESCR, 
       NZ((SELECT SUM(tF.FC_HEATCONTENT) FROM FIXED as tF 
            WHERE (tPA.[PA_NAME] = tF.[PA_NAME]))) AS FC_HEATCONTENT,
       NZ((SELECT SUM(tT.TC_HEATCONTENT) FROM TRANSIENT as tT
           WHERE (tPA.[PA_NAME] = tT.[PA_NAME]))) AS TC_HEATCONTENT,
       NZ((SELECT SUM(tCT.CT_HC) FROM CABLE_TRAYS AS tCT
           WHERE (tPA.[PA_NAME] = tT.[PA_NAME]))) AS CT_HC,
       tPA.FLOOR_AREA, 
       tPA.PA_COMMENT
    FROM  PLANT_AREAS as tPA 
    WHERE (tPA.[PA_NAME]) Like [Forms]![Combustible Summary Report Parameters]![Combo45]));

  7. #7
    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,726
    Do you have a data model (tables and relationships diagram)?
    Perhaps you could post a copy as a jpg.

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

Similar Threads

  1. records number shows in label
    By mathanraj76 in forum Programming
    Replies: 3
    Last Post: 04-24-2013, 07:37 PM
  2. Replies: 1
    Last Post: 01-11-2013, 06:01 PM
  3. combining records to show as one in a report.
    By mejia.j88 in forum Reports
    Replies: 1
    Last Post: 04-10-2012, 04:18 PM
  4. Subreport shows all records
    By wubbit in forum Reports
    Replies: 6
    Last Post: 04-05-2012, 07:04 AM
  5. show 4 records in each report page
    By kareem_h in forum Reports
    Replies: 5
    Last Post: 11-10-2010, 10:11 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