Results 1 to 6 of 6
  1. #1
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313

    Select Just First Header/Detail Row


    I have two tables with the typical Header/Detail relationship. In this instance the first detail for each header has special significance. I would like to write a query that lists a series of header/detail combinations, but only the first detail for each header. Thanks in advance, Eddie

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Show examples of raw data and desired output.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313
    Not sure how to give an example, but I'll try... I'm printing a Purchase Order Summary report with one line per PO. Each line contains PO Number, Date, etc. plus I want to include the first detail whose field named Comment start with the string "Note:". Usually this is the first detail, but not always... sometimes there aren't any details like this at all. So, here are three sample lines:

    PO Nbr Date Comments
    1234 2/13/14 Note: See attach pdf file
    1235 2/13/14 [blank... no "Note:" details]
    1236 2/13/14 Note: Provide extra padding

    Does this help? Thanks, Eddie

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Not quite. Is that the raw data or output example? You show 3 records, each is a different PO Nbr. Does this mean you want all 3 Comments to return? There would be other records for each PO Nbr that you don't want the comments from?

    A table can be built in post with the Advanced post editor.

    Or can attach files. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313
    This is the output example. Typical one header with multiple details. I want to show the header fields as well as the Comment from the first detail whose Comment field begins with "Note:", otherwise blank.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Still not fully understanding the data structure. There are two tables involved - primary and dependent? Can there be comments that do not begin with Note? Can there be more than one Note: for each PONbr/Date combination?

    Maybe an aggregate (Totals) GROUP BY query will get you what you want.

    Build a query that joins the two tables.

    Select the PONbr and Date.

    Create a field with expression:

    NoteComment: IIf([Comment] LIKE "Note:*", [Comment], Null)

    Click the Totals button on ribbon.

    Set PONbr and Date to GROUP BY.

    Set NoteComment to MAX.

    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention. Also, should avoid reserved words as names. Date is a reserved word.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 9
    Last Post: 04-21-2013, 05:37 PM
  2. Replies: 1
    Last Post: 04-14-2013, 07:01 PM
  3. Scroll Detail While Freezing Header
    By EddieN1 in forum Forms
    Replies: 2
    Last Post: 02-03-2013, 08:34 PM
  4. Replies: 0
    Last Post: 06-29-2009, 10:28 PM
  5. Space Between Header and Detail in Report
    By tigers in forum Reports
    Replies: 3
    Last Post: 06-23-2009, 12:01 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