Results 1 to 8 of 8
  1. #1
    giblets is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    21

    Concatenate Field or Group by in Report or or or?

    I'm looking for a way to summarize multiple fields of data from the same column in a single field. I've seen this page but have been unable to get it to work. I save the code listed but do not know which of the example fields would relate to my table.

    Code:
    SELECT CompanyName,  ConcatRelated("OrderDate", "tblOrders", "CompanyID = " & [CompanyID]) 
        FROM tblCompany;
    I saw that I can create a report and select "group by," but then all the columns appear on different lines rather than summarized on one line. Here is an example of how I would like the data to appear, separated by commas or with specific dates within parentheses. The reason I want them all on one line is to provide an easier to read/more succinct summary.

    e.g.
    ITEM LOCATION DATE
    GORP EAST 1/1/2012
    GORP EAST 2/1/2012
    GORP WEST 1/1/2012
    FLORP WEST 1/1/2012



    displayed as:
    ITEM LOCATION DATE
    GORP EAST 1/1/2012, 2/1/2012
    GORP WEST 1/1/2012
    FLORP WEST 1/1/2012

    or (even better):
    ITEM LOCATIONandDATE
    GORP EAST (1/1/2012, 2/1/2012), WEST (1/1/2012)
    FLORP WEST (1/1/2012)

    not as:
    ITEM LOCATION DATE
    GORP EAST 1/1/2012
    2/1/2012
    GORP WEST 1/1/2012
    FLORP WEST 1/1/2012

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    VBA code is only way I know to do this. The link you reference provides sample code. I created a table of the posted example data. This query produces the first concatenated output:

    SELECT DISTINCT ITEM, LOCATION, ConcatRelated("[Date]","tblCompany","ITEM='" & [ITEM] & "' AND LOCATION='" & [LOCATION] & "'","ITEM, LOCATION") AS DATES
    FROM tblCompany;

    Then I saw that your attempt includes CompanyID and the date fieldname is different. Try this:

    SELECT DISTINCT tblCompany.CompanyID, tblCompany.ITEM, tblCompany.LOCATION, ConcatRelated("[OrderDate]","tblCompany","CompanyID=" & [CompanyID] & " AND ITEM='" & [ITEM] & "' AND LOCATION='" & [LOCATION] & "'","CompanyID, ITEM, LOCATION, OrderDate") AS DATES
    FROM tblCompany;

    Could adjust code for the result shown in your second output example or use first query in another query:

    SELECT DISTINCT Query1.CompanyID, Query1.ITEM, ConcatRelated("Location & ' (' & Dates & ')'","Query1","CompanyID=" & [CompanyID] & " AND ITEM='" & [ITEM] & "'","CompanyID, ITEM, Location, Dates") AS LocDates
    FROM Query1;
    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
    giblets is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    21
    CompanyID? The code I posted was copy/pasted from the website, not something that relates to my data.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Then show your attempted code (the query SQL statement) that uses your fieldnames. Why doesn't it work - error message, wrong results, nothing happens? Did you even try the first query I suggested but using your actual table and field names?
    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
    giblets is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    21
    Thanks for the help so far, I'm still fiddling with it so far and will report back if (when) I have more questions!

  6. #6
    giblets is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    21
    Cool stuff. See attached example.

    How can I make items within concatenated fields appear in alphabetical or chronological order?

    test.2012-1218.accdb.zip

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Include COLLDATE in the function's ORDER BY argument.

    SELECT DISTINCT Collections.SPECIES, Collections.COLLFROM, ConcatRelated("[COLLDATE]","Collections","SPECIES='" & [SPECIES] & "' AND COLLFROM='" & [COLLFROM] & "'","SPECIES,COLLFROM,COLLDATE") AS COLLDATE
    FROM Collections;
    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.

  8. #8
    giblets is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    21
    MAGIC. Thanks again!

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

Similar Threads

  1. Reset autonumber in a concatenate field
    By Fish218 in forum Forms
    Replies: 6
    Last Post: 03-13-2012, 11:58 AM
  2. Replies: 1
    Last Post: 11-01-2011, 05:55 PM
  3. Replies: 6
    Last Post: 04-07-2011, 12:33 PM
  4. Group report by a multivalued lookup field
    By jonsons in forum Reports
    Replies: 0
    Last Post: 12-01-2009, 04:08 PM
  5. Concatenate two fields (text & number) for key field
    By Larry Elfenbein in forum Forms
    Replies: 2
    Last Post: 11-10-2005, 07:45 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