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 
Grouping Record
John Yeung 
     
4 years ago
How to group Table 1 to Table 2 (below) in Access ? use query ?
John Yeung OP  @Reply  
     
4 years ago

Kevin Robertson  @Reply  
          
4 years ago
Adam Schwanz  @Reply  
           
4 years ago
Are you joining two tables? Or is it one table and you want to show the results from one table as one record with 3 numbers instead of 3 records with 1 number in the case of customer 1?

What is the purpose of this? Just for display on a form? I would use a For Next Loops probably. Or a recordset. Or both. Make a string and add onto it everytime it gets a new number.
Kevin Yip  @Reply  
     
4 years ago
To turn Table1 into Table2, you need to create a custom function with VBA, then create a "group by" query.  I think Richard has done videos for both topics.  Hopefully someone will point you to them.

The custom VBA function would look something like below.  It loops through a recordset of all the phones of the specified customer and create a comma-delimited string of them.  You need to know how to manipulate recordsets with VBA.  Richard may have a developer video for that too:

Function GetAllPhones(customer As Integer) As String
    Dim r As Recordset, s As String
    
    ' Create recordset of all phones for the specified customer.
    Set r = CurrentDb.OpenRecordset("SELECT phone FROM Table1 WHERE customer=" & customer)
    
    s = ""
    
    ' Move to first record.
    r.MoveFirst
    
    ' If last record hasn't been reached, run do loop below.
    Do While Not r.EOF
    
        ' If s is not empty, add a comma.
        If Len(s) > 0 Then s = s & ", "
        
        ' Append phone in current record to s.
        s = s & r!phone
        
        ' Go to next record.
        r.MoveNext
    Loop
    
    ' Return resulting string.
    GetAllPhones = s
        
End Function


Then you use the above function in a "group by " query:

SELECT Table1.customer, GetAllPhones([customer]) AS phones
FROM Table1
GROUP BY Table1.customer;
Juan C Rivera  @Reply  
            
4 years ago
John Yeung OP  @Reply  
     
4 years ago
It seems that it is not union query

I just want to print Table 1 in a small label, it will be too tall to have phones line up like this

therefore I just want it to line up like Table 2 for easy label printing
Richard Rost  @Reply  
          
4 years ago
Use my DlookupPlus function that Juan recommended.

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: 6/22/2026 9:22:45 PM. PLT: 1s