Results 1 to 13 of 13
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209

    Merge Multiple Rows To Single Row

    I have a table that has a row entry for each userID. I need a way to display each userID on one line in a query. Data is set-up like this
    Code:
    userid logonstation
    123     e12ac
    123     rst22
    123     ffk8
    456     99a
    456     781e
    789     r289
    789     n11
    789     n132
    789     n08
    789     n22
    I want my output to be like so


    Code:
    userid  ls1     ls2     ls3     ls4     ls5
    123    e12ac  rst22   ffk8
    456    99a     781e    
    789    r289    n11     n132  n08    n22
    How can I use a standard query or even VBA to be able to have query results display like the above?

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    try the crosstab query wizard. It may not be what you need because the number of columns output by the query depends on the underlying data, which means you can have more or less each time you run it. Saying this because I have no idea where you got the field headers from.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Another option, if you don't need the values in separate fields:

    http://allenbrowne.com/func-concat.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529

  5. #5
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Quote Originally Posted by Micron View Post
    try the crosstab query wizard. It may not be what you need because the number of columns output by the query depends on the underlying data, which means you can have more or less each time you run it. Saying this because I have no idea where you got the field headers from.

    For the field headers I just shortened logonstation to ls and appended a number to the end. Looking at a cross tab query - I did not see a way to get all the data for each userid on ONE line like I am needing...

  6. #6
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Quote Originally Posted by pbaldy View Post
    Another option, if you don't need the values in separate fields:

    http://allenbrowne.com/func-concat.html
    In the end I would need the data in two seperate fields, but if I can add to one line I could run a make table query to split at a delimeter.

    However, Access 2013 tells me invalid function if I try to run (of course replacing with my field names)
    Code:
    ConcatRelated("OrderDate", "tblOrders", "CompanyID = " & [CompanyID]) 

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Did you copy the function to a standard module, and make sure the module doesn't have the same name?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    @PBadly - yes I did.

    Sample database attached.
    Attached Files Attached Files

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Where did you try it? There's no object here it could be used in. Runs fine for me in a test query:

    SELECT DISTINCT test.employeeID, ConcatRelated("Event","test","EmployeeID = '" & [EmployeeID] & "'") AS Whatever
    FROM test;
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    I want to run it on all employeeID that exist in the table. I was omitting the 3rd parameter in the syntax you have above. Is it possible to perform with all employeeID in the table?

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Not sure what you mean. That will return all employees. On the sample it returns:

    employeeID Whatever
    bc84 run, hop
    bj22 skip, run, hop
    ems11 run, bangles, stank, hop
    mp11 three, run, skip
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    @pbaldy - my mistake I thought the last parameter was requesting input from a combo box etc. That is what I was after, thank you!

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 10-22-2016, 12:30 PM
  2. Replies: 5
    Last Post: 03-06-2015, 02:04 PM
  3. Replies: 1
    Last Post: 04-14-2014, 12:29 PM
  4. Replies: 7
    Last Post: 10-30-2012, 02:18 PM
  5. Replies: 5
    Last Post: 04-10-2012, 08:53 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