Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
concatenate rows
John Yeung 
     
4 years ago
How to concatenate:

ColumnA ColumnB
1       abc
1       pqr
1       xyz
2       efg
2       hij
3       asd

    into :

ColumnA ColumnB
1       abc, pqr, xyz
2       efg, hij
3       asd


thanks
Kevin Robertson  @Reply  
          
4 years ago
DLookupPlus.

Class: Access Developer 17
Code Vault: DLookupPlus
Kevin Yip  @Reply  
     
4 years ago
Hi John, this seems quite a popular topic, as I've answered this query a few times in recent weeks, and twice in the past 24 hours.   Basically you need to write a custom function in VBA that reads through the necessary records with a Recordset loop and construct a comma-delimited string from those records.  Then you use this custom function in a query or other VBA code to get the result you desire.  My pictures show an example of this.  I remember you said you were also an SQL Server user.  SQL Server has a (much) easier way to do this, shown in my second pic below (done with a "passthrough query" in Access).  I don't have access to Richard's Code Vault, so the methods cited by Kevin above may be different from mine.
Kevin Yip  @Reply  
     
4 years ago

Kevin Yip  @Reply  
     
4 years ago

John Yeung OP  @Reply  
     
4 years ago
Dear Robertson,
I used the code vault and gave Error in the field , any idea ?
John Yeung OP  @Reply  
     
4 years ago

John Yeung OP  @Reply  
     
4 years ago

John Yeung OP  @Reply  
     
4 years ago
Dear Yip,
Do you have a simpler custom function in VBA ? I just have 2 columns to combine, no dates, no units to add
Really is like above column A and column B
Thanks again
Kevin Yip  @Reply  
     
4 years ago
I can't think of a simpler function or methodology.  And some of the code from the code vault is not straightforward either.  You often can't just use other people's code verbatim, and have to adapt from it.

No matter how simple your table's structure is, my method still requires using a Recordset loop, processing each record, adding commas after them, and checking for empty values before adding commas.  A function with only ten lines is not the most complex of functions.  If you use SQL Server, then my second method is the simplest, with only one SQL statement.
Kevin Robertson  @Reply  
          
4 years ago
Hi John,

I've put together a screenshot using the sample data in your initial post as an example of how to set this up.
Kevin Robertson  @Reply  
          
4 years ago

John Yeung OP  @Reply  
     
4 years ago
done. thanks Robertson. you are just great
John Yeung OP  @Reply  
     
4 years ago
thanks Yip too. I really appreciate your help but I am not that smart to transpose your code to use.
Richard Rost  @Reply  
          
4 years ago
John, you're a gold member. Use the DLookupPlus function.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 6:29:25 PM. PLT: 1s