Results 1 to 8 of 8
  1. #1
    Maikel is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Paramaribo, Suriname
    Posts
    4

    Post Join cells from two or more rows in one cell

    Dear All,

    Is it possible to join cell content from two or more rows into one cell? see below:

    Location(key) Sample(key) Property1 Property2
    South-America 1 Blue White
    South-America 2 Black White
    South-Amarica 3 Blue White
    Africa 1 Blue Black
    Africa 2 Blue White

    After query:
    Location(key) Sample(key) Property1 Property2
    South-America 1(first) Blue-Black White
    Africa 1(first) Blue White-Black

    thanks in advance,



    Maikel

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I have done what you are trying using VBA.
    I don't know of a way to do it in a Query

    Can you explain exactly what you need as an end product?

    What is the meaning of "(first)" here:
    South-America 1(first) Blue-Black White
    Africa 1(first) Blue White-Black

  3. #3
    Maikel is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Paramaribo, Suriname
    Posts
    4
    Thanks Robeen.

    I have a database holding data for an experiment where a maximum of four samples are taken (four records). Each record is indentified by a composite key with made up of 5 fields. In addition to those 5 key fields I have 14 other fields of which some are numbers and some are text fields.

    I created a select query in which I use the totals function to calculate means for the Numbers, but I also want bring the text values together in one field. To do that is use the option "Group by first" (not the best option of course) . But since the text values differ i want to be able to just add all of them together in that one field, thus bringing together the maximum of four rows into one row.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Can you paste your Select Query here so we can look at it?

  5. #5
    Maikel is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Paramaribo, Suriname
    Posts
    4
    SELECT tblLeaf_i.[TRIAL_NO], tblLeaf_i.[BANK_LOC], tblLeaf_i.[ACC_NO], First(tblLeaf_i.[SAMP_NO]) AS EersteVanSAMP_NO, tblLeaf_i.[REP_NO], First(tblLeaf_i.[PLNT_NO]) AS EersteVanPLNT_NO, First(tblLeaf_i.[CHR_DTE]) AS EersteVanCHR_DTE, First(tblLeaf_i.[PLNT_DTE]) AS EersteVanPLNT_DTE, First(tblLeaf_i.[FLOWERS]) AS EersteVanFLOWERS, Avg(tblLeaf_i.[LF_SCARS]) AS GemVanLF_SCARS, Avg(tblLeaf_i.[PT_ANGLE]) AS GemVanPT_ANGLE, First(tblLeaf_i.[APL_COL]) AS EersteVanAPL_COL, First(tblLeaf_i.[FFXL_COL]) AS EersteVanFFXL_COL, First(tblLeaf_i.[PT_COL]) AS EersteVanPT_COL, First(tblLeaf_i.[LV_COL]) AS EersteVanLV_COL, First(tblLeaf_i.[YL_PUBE]) AS EersteVanYL_PUBE, Avg(tblLeaf_i.[PT_LNGTH]) AS GemVanPT_LNGTH, Avg(tblLeaf_i.[LB_NUM]) AS GemVanLB_NUM, First(tblLeaf_i.[CNTR_LS]) AS EersteVanCNTR_LS, Avg(tblLeaf_i.[LB_LNGTH]) AS GemVanLB_LNGTH
    FROM tblLeaf_i
    GROUP BY tblLeaf_i.[TRIAL_NO], tblLeaf_i.[BANK_LOC], tblLeaf_i.[ACC_NO], tblLeaf_i.[REP_NO];

    This is the result of my select query in SQL view. I'm using a dutch version of ms access, so "Eerstevan" just means FirstOf and "GemVan" means AverageOf.

  6. #6
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Hi Maikel!

    I read through this entire thread again - just to see if there was something I had missed before. I couldn't find anything that I had missed.

    I have done what you are trying to do using a Function in a Module [the Function gets called from a Macro]. The Function uses a SQL query recordset and loops through the records and processes the data to produce results similar to what you need. I would be happy to help you with that.

    Meanwhile, here is another way of achieving what you are trying:
    http://stackoverflow.com/questions/2...-i-want-to-run

    I have not tried the above but it looks like it would achieve what you need even though the way I did it is different.

    Let me know if this helps.

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    you can do this with a crosstab query if the 'color' field doesn't all have to be in the same field.

    That way you could also control the order (alphabetical or some other order if you set it up correctly)

    What a crosstab can do is take your original data:

    Code:
    Location      Sample Property1 Property2
    South-America 1      Blue      White
    South-America 2      Black     White
    South-America 3      Blue      White
    Africa        1      Blue      Black
    Africa        2      Blue      White
    And and turn it into this:

    Code:
    Location       Black Blue White
    South-America  1     2    3
    Africa         1     2    1
    Where you can count the number of instances the item occurs in the list as well. Or you can actually show the label


    Code:
    Location       Black Blue White
    South-America  Black Blue White
    Africa         Black Blue White
    And if you had an item that was missing a 'color' there would just be a blank field.

  8. #8
    Maikel is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Paramaribo, Suriname
    Posts
    4
    Well rpeare, i will look at that posibility.

    Also Robeen, thanks for the link. You think i could take a look at that code of yours?

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

Similar Threads

  1. Returning correct rows in a join/nested query
    By goneaccessing in forum Queries
    Replies: 5
    Last Post: 03-03-2010, 12:21 PM
  2. Condensing Rows of Data into one Cell
    By alexandermorris in forum Access
    Replies: 1
    Last Post: 02-25-2010, 07:47 AM
  3. Combine multiple rows into one cell
    By zarfx4 in forum Queries
    Replies: 8
    Last Post: 06-08-2009, 10:42 AM
  4. Replies: 1
    Last Post: 03-02-2009, 10:12 PM
  5. Can we post Access cell data to Excel cell properties?
    By Zethro in forum Import/Export Data
    Replies: 1
    Last Post: 12-13-2005, 08:42 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