473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Combining Memo field from multiple records into one field

1
Hi Guys, I am a newbie and need some help.

I have a query that contains a list of questions together with the result per question for a group of learners.
Example: Learner ID; Name, Surname, Question; Result and Comment.

If I run the query on one particular learner, there might be 5 records, each with a comment. I need to combine these comments into one field.
Example: 1st comment followed by 2nd commentfollowed by 3rd comment followed by 4th comment followed by 5th comment.

I need to display the records as well as this one field in a form. Can anyone help?

Thank you.
May 3 '10 #1
2 5095
Jim Doherty
897 Expert 512MB
@allanb
I see you have not had a contribution on this for a week.

Some advice do not use NAME as a word for naming fields. It is a reserved word and can cause problems. I notice you mention a query, my assumption is that your data is normalised properly and that your query gathers its source data from separate tables.

To help you, below is a function that expects a numeric 'learnerID' data type of the datatype LONG INTEGER to be passed to it. (If yours is text then it will have to be reflected in the SQL string where the LearnerID is mention)

To get this working open a New Module and paste the function directly into it and save it

The function now becomes available to your query in that you can add it as any other column for instance in the query grid just type in a new column the fieldname as

All Comments: CommentsAll([LearnerID])

and it will return the concatenation of ALL comments but it will display it for EACH row too. This is not so painful to look at if you are simply creating a form that displays a single question record. You can assign place a textbox on the form and set its controlsource to the additional column 'All Comments'

Below is the function

Expand|Select|Wrap|Line Numbers
  1. Function CommentsAll(learnerId As Long) As String
  2. 'loop a column of comments depending on the NUMERIC value of learnerid passed
  3. 'to the function and list the comments per record.
  4. 'but concatenated so that is is a list format suitable of use in a textbox
  5. 'the learnerid is assumed nueric value and that it exists in each row to identify
  6. 'the row.  If you dont want the vbNewline then replace with Space(1)
  7. Dim db As DAO.database
  8. Dim rs As DAO.Recordset
  9. Dim str As String
  10. Dim mysql As String
  11. Set db = CurrentDb
  12. mysql = "SELECT Comment FROM tblLearner WHERE (((tblLearner.LearnerID)=" & learnerId & "));"
  13. Set rs = db.OpenRecordset(mysql, dbOpenDynaset)
  14. If rs.RecordCount <> 0 Then
  15. i = 1
  16.     Do While Not rs.EOF
  17.         str = str & UCase("This is the comment for question (" & i & ")") & vbNewLine
  18.         str = str & Nz(rs!Comment, "(No comment given)") & vbNewLine
  19.         rs.MoveNext
  20.     i = i + 1
  21.     Loop
  22. End If
  23. Debug.Print str
  24. CommentsAll = str
  25. rs.Close
  26. db.Close
  27. Set rs = Nothing
  28. Set db = Nothing
  29. End Function
May 10 '10 #2
NeoPa
32,556 Expert Mod 16PB
Combining Rows-Opposite of Union may help.
May 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
5
by: crispy | last post by:
On this page, you'll see that some PubID's are repeated several times: http://www.ihea.info/pages/website/test1.asp That's because some records have more than one attribute. For example, Title...
0
by: glenn | last post by:
I'm really scratching my head over this one. I'm working with CSV data exported from Excel, which explains why it's a mess to begin with. Within a table (or via any other means someone might be...
5
by: sling blade | last post by:
Hi, I have an web app and I am using access 2002 and VB.net. I am using a data adapter to fill a dataset. I am retrieving product descriptions, some are long and i have used a field of memo...
4
by: Terren | last post by:
Is there a way to create one field from multiple records using sql. For example Table 1 John 18 Peter 18 David 18 Now I want an sql query that when executed will return a field that...
3
by: chalrav | last post by:
Reading through multiple records, with Loop capability -------------------------------------------------------------------------------- Hi, I have three tables as below: Table: Demand...
4
4Him
by: 4Him | last post by:
First off, let me say this is a great site! I've just started working with Access and much of my success is from what I've read here! Background: I have a form, driven off a single table. Goal:...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
0
by: t8ntboy | last post by:
ASP/SQL Server Express 05 I have two tables, A and B. I would like to insert multiple records into both form A and B, but a field in form B is the Record ID in form A. So, I need to insert the...
5
by: lucyh | last post by:
I have a table which I have added another field to. This field has a default value of NA and although any new entries will automatically have the default value of NA, I need to enter NA in all the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.