Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining values from the same field in an Access query?

Status
Not open for further replies.

sellert

Programmer
Nov 18, 2004
36
US
I have an application that has documents, the users can add comments for a particular document, this creates a one to many relationship. Now I am trying to run a routine that will create metrics and the users want to see all of the comments. I don't want the document to be listed more than once. This means I need to have all of the comments print together for the one time listing of the document.

In an Access query how do I combine several records for a document into one so I can use it in the report?

Thanks,
SELLERT

If I'm not learning I must be coasting. If I am coasting I must be going down hill.
 
How are ya sellert . . .

This is quite a different perspective from your latest post in thread705-1349969.

What you need is a function that returns the fully concatenated comments and with at least a full line space between each! Just incase users include a line space(s) in their comments the following function pre-appends each comment with [blue]*** New Comment ***[/blue]. Understand since I don't know your table structure, this is just a shot! . . .
Code:
[blue]Public Function PackComments(ID As Long) As String
   Dim db As Database, rst As DAO.Recordset, SQL As String, Build As String
   Dim Msg As String, Style As Integer, Title As String, DL As String
   
   Set db = CurrentDb
   DL = vbNewLine & vbNewLine
   SQL = "SELECT Comments " & _
         "FROM TableName " & _
         "WHERE CommentsID = " & ID & ";"
   Set rst = db.OpenRecordset(SQL, dbOpenDynaset)
   
   If rst.BOF Then
      Msg = "No Comments for this record!"
      Style = vbInformation + vbOKOnly
      Title = "No Comments Detected! . . ."
      MsgBox Msg, Style, Title
   Else
      Do Until rst.EOF
         If Build <> "" Then
            Build = Build & DL & rst!Comments
         Else
            Build = rst!Comments
         End If
         
         rst.MoveNext
      Loop
   End If
   
   PackComments = Build
   
   Set rst = Nothing
   Set db = Nothing
   
End Function[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Sellert, otside of Ace's code, you consider either
using "Totals/Grouping" query(toggling the Sum icon
on the menu bar, in the query pane), or just downright
use the grouping properties on the report,
from design view (preferred!).
 
Have a look here:
faq701-4233

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I need to do this outside of code within the access query design view. Also, I know oder than dirt - I am using access 97. To be converted soon though.

Thanks,
SELLERT

If I'm not learning I must be coasting. If I am coasting I must be going down hill.
 
I need to do this outside of code
So, why asking in the Access Modules (VBA Coding) Forum ?
 

Create your query with both fields as output.
Build a new form or report based on the query.
Show the document name once, such as in the form header.
Display all comments, such as in a continuous form.


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top