473,657 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Build comma-delimited list from table

I have a table that looks like this:

Forest Residents
Black Josh
Black Joellen
Black Mary Jane
Brown Gertrude
Brown Josh
Brown Mary Jane
I've seen some UDFs for SQL Server to build a comma-delimited list, but
I need a function to use entirely in Access to build the following:

Residents Forests
Josh Black, Brown
Joellen Black
Mary Jane Black, Brown
Gertrude Brown

The table above indicates the forests each person has visited in a
comma-delimited list.

Any suggestions?

Nov 13 '05 #1
22 13647
Per ar****@yahoo.co m:
Residents Forests
Josh Black, Brown
Joellen Black
Mary Jane Black, Brown
Gertrude Brown

The table above indicates the forests each person has visited in a
comma-delimited list.


If I were doing it, I'd open up the source table sorted by Person/Forest and
just iterate through the table, concatenating PersonName|Tab| ForestName into a
string variable - and flushing the string to disk each time PersonName changes
(not forgetting to flush the last one at .EOF)
--
PeteCresswell
Nov 13 '05 #2
"(PeteCresswell )" <x@y.z.invalid. USA> wrote in
news:u2******** *************** *********@4ax.c om:
Per ar****@yahoo.co m:
Residents Forests
Josh Black, Brown
Joellen Black
Mary Jane Black, Brown
Gertrude Brown

The table above indicates the forests each person has visited
in a comma-delimited list.


If I were doing it, I'd open up the source table sorted by
Person/Forest and just iterate through the table,
concatenating PersonName|Tab| ForestName into a string variable
- and flushing the string to disk each time PersonName changes
(not forgetting to flush the last one at .EOF)


That's exactly how Dev Ashish wrote the fConcatChild function
http://www.mvps.org/access/modules/mdl0004.htm

Why reinvent the wheel?

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #3

ar****@yahoo.co m wrote:
I have a table that looks like this:

Forest Residents
Black Josh
Black Joellen
Black Mary Jane
Brown Gertrude
Brown Josh
Brown Mary Jane
I've seen some UDFs for SQL Server to build a comma-delimited list, but
I need a function to use entirely in Access to build the following:

Residents Forests
Josh Black, Brown
Joellen Black
Mary Jane Black, Brown
Gertrude Brown

The table above indicates the forests each person has visited in a
comma-delimited list.

Any suggestions?

Firstly, I'm assuming their is a "ResidentID " field in your many table
above and it looks as follows:

ResidentID Forest Residents
1 Black Josh
2 Black Joellen
3 Black Mary Jane
4 Brown Gertrude
1 Brown Josh
3 Brown Mary Jane

If so, put the following function (a modified version of one by Allen
Browne) into a module:

Function ConcatDetail(Nu m As Long) As Variant
Dim MyDB As Database
Dim rst As Recordset
Dim strOut As String
Dim strSql As String
Dim lngLen As Long

Const strcSep = ","

Set MyDB = CurrentDb()

'Change Table1 to your table's name
strSql = "SELECT Forest FROM Table1 WHERE ResidentID = " & Num & ";"
Set rst = MyDB.OpenRecord set(strSql)
With rst
Do While Not .EOF
strOut = strOut & !Forest & strcSep
.MoveNext
Loop
End With
rst.Close

lngLen = Len(strOut) - Len(strcSep)
If lngLen > 0 Then
ConcatDetail = Left(strOut, lngLen)
Else
ConcatDetail = Null
End If

Set rst = Nothing
Set MyDB = Nothing
End Function
Next, Create a query on the table (Your 1st table shown above and
called Table1 in this example). Add the "Resident" field and create
another field beside this e.g.

Forests: ConcatDetail([ResidentID])

Run this query and you should see what you require.

osmethod

Nov 13 '05 #4
Per Bob Quintal:
That's exactly how Dev Ashish wrote the fConcatChild function
http://www.mvps.org/access/modules/mdl0004.htm

Why reinvent the wheel?


I must've misunderstood the OP.

I thought all the data were in a single table - with multiple records for each
person depending on how many forests.
--
PeteCresswell
Nov 13 '05 #5
You should also set "Unique Values" to yes in the query.....

osmethod

Nov 13 '05 #6
"(PeteCresswell )" <x@y.z.invalid. USA> wrote in
news:os******** *************** *********@4ax.c om:
Per Bob Quintal:
That's exactly how Dev Ashish wrote the fConcatChild function
http://www.mvps.org/access/modules/mdl0004.htm

Why reinvent the wheel?


I must've misunderstood the OP.

I thought all the data were in a single table - with multiple
records for each person depending on how many forests.


That's exactly what fConcatChild() expects. It goes thrugh the
table, adding the value from each record to a list, where the
filter would be based on the person field.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #7
Yes I am trying to implement this With the source data all in one table
..I'm not sure how to implement this given the info you provided.
Bob Quintal wrote:
"(PeteCresswell )" <x@y.z.invalid. USA> wrote in
news:os******** *************** *********@4ax.c om:
Per Bob Quintal:
That's exactly how Dev Ashish wrote the fConcatChild function
http://www.mvps.org/access/modules/mdl0004.htm

Why reinvent the wheel?


I must've misunderstood the OP.

I thought all the data were in a single table - with multiple
records for each person depending on how many forests.


That's exactly what fConcatChild() expects. It goes thrugh the
table, adding the value from each record to a list, where the
filter would be based on the person field.

--
Bob Quintal

PA is y I've altered my email address.


Nov 13 '05 #8
"(PeteCresswell )" <x@y.z.invalid. USA> wrote in
news:u2******** *************** *********@4ax.c om:
Per ar****@yahoo.co m:
Residents Forests
Josh Black, Brown
Joellen Black
Mary Jane Black, Brown
Gertrude Brown

The table above indicates the forests each person has visited in a
comma-delimited list.


If I were doing it, I'd open up the source table sorted by
Person/Forest and just iterate through the table, concatenating
PersonName|Tab| ForestName into a string variable - and flushing
the string to disk each time PersonName changes (not forgetting to
flush the last one at .EOF)


Why not just SELECT DISTINCT, then you don't have to code to check
when the name changes?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9
os******@eircom .net wrote in
news:11******** **************@ f14g2000cwb.goo glegroups.com:
You should also set "Unique Values" to yes in the query.....


And you should also probably remove the ones that have Null or
zero-length string in the field you're concatenative, or you'll get
consecutive commas.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
4558
by: Alberto Vera | last post by:
Hello: I have the next structure: How Can I make it using Python? How Can I update the value of 6?
8
5719
by: Deepa | last post by:
I am writing a console app in c# wherein am converting a dataset into a CSV file. It works fine. But I have some values in the dataset which have a comma within(eg. A,B,C). When I view the CSV file in Excel, the multiple values which are separated by the 'comma' in the dataset are being displayed in the next column , which I dont want that way. I want to retain any commas which are present in my dataset. How do I handle such a scenario? ...
5
2559
by: Derek | last post by:
I came upon the idea of writting a logging class that uses a Python-ish syntax that's easy on the eyes (IMO): int x = 1; double y = 2.5; std::string z = "result"; debug = "Results:", x, y, z; The above example outputs:
3
1864
by: SteelDetailer | last post by:
Thnaks in advance for considering this post. It's probably very simple, but..... I have an old VB6 application that allows me to create, save and edit a "project information file" that is a simple .txt file. I then use that file to keep the project information current for the multiple AutoCAD drawings that project requires. My problem.....several of the items I save are company names (customers). Many times company names have commas...
6
1887
by: D | last post by:
How do you put a comma in a string that's passed as a function argument. The compiler thinks it's the end of that argument and I've tried the /, and "," but they don't seem to work.
4
2194
by: G Patel | last post by:
Hi, I've read a book on C, and I understand how comma operators work, but my book didn't say that the comma operators between function arguments were not really comma operators (even though it seems obvious to me that comma operators would serve no purpose between function arguments). As per C, are those commas in function argument lists the same comma operators? Also, are the =s used in initializations the same as any other
3
6059
by: Michael Yanowitz | last post by:
Hello: I am still relatively new to Python. I am confused by the syntax for tuples. I had: thread.start_new_thread(read_data_thread, (strDataFilename)) and got back the following error: File "scene.py", line 256, in readData thread.start_new_thread(read_data_thread, (strDataFilename))
7
12612
by: MattyWix | last post by:
Hi, How can I pass a semicolon or a comma as a macro argument. I wish to build an expression that in some cases has a comma - eg building a list of members for a structure, but in other instances has a comma - eg building a list of arguments for a function. MattyWix
15
2624
by: Lighter | last post by:
In 5.3.3.4 of the standard, the standard provides that "The lvalue-to- rvalue(4.1), array-to-pointer(4.2),and function-to-pointer(4.3) standard conversions are not applied to the operand of sizeof." I think this rule is easy to understand. Because I can find the contexts of applying the rule as follows. (1) int* p = 0; int b1 = sizeof(*p); // OK, b1 = 4, *p would not be evaluated.
6
3144
by: lazukars | last post by:
Hi, I am attempting an ajax request. I am using PHP serverside. Below is what the response text should be. ajaxRequest.responseText ="{username_is_taken : "This username has been taken",}" However, the only way I can get the responseText to work on a website via an alert is to take out the comma before the curly bracket. By taking out I mean just not printing the comma with the rest of the string in PHP. If I take out this comma...
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.