473,416 Members | 1,716 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,416 software developers and data experts.

Filtered Colum To Single Comma Delimited Value??

Is it possible in Access to do the following.
I filtered my table to have the folowing values

ProdID Color
------------------------
2 Black
2 Red
2 Green

Now is it possible to create a view that only displaces 1 unique row
with the color column as comma separater like the following
ProdID Color
2 Black, Red, Green

I need help on this. Anything would be appreciated.
Thank
K

Dec 15 '05 #1
1 1394
kchatel wrote:
Is it possible in Access to do the following.
I filtered my table to have the folowing values

ProdID Color
------------------------
2 Black
2 Red
2 Green

Now is it possible to create a view that only displaces 1 unique row
with the color column as comma separater like the following
ProdID Color
2 Black, Red, Green

I need help on this. Anything would be appreciated.
Thank
K


I'll give a brute force example that seems to work using DAO and should
suffice until others suggest more elegant methods.

tblColors
ColorID AutoNumber PK
ColorName Text
ColorID ColorName
1 Black
2 Red
3 Green
4 Blue
5 Yellow

tblProducts
ProductID AutoNumber PK
ProductName Text
SKU Text (Indexed, No Duplicates)
ProductID ProductName SKU
1 Product1 SKUC
2 Product2 SKUB
3 Product3 SKUA

tblProductColors
PCID AutoNumber PK
ProductID Long FK
ColorID Long FK
SortOrder Long
PCID ProductID ColorID SortOrder
1 2 1 1
2 2 2 2
3 2 3 3
4 3 5 2
5 3 4 1

'-----Begin Module Code
'These are my Module Options:
'Option Compare Database
'Option Explicit

Public Function GetProductColors(lngProductID As Long) As String
Dim MyDB As DAO.Database
Dim ColorRS As DAO.Recordset
Dim strSQL As String
Dim strTemp As String
Dim lngColorCount As Long
Dim lngI As Long

strTemp = ""
strSQL = "SELECT ColorName FROM (tblColors INNER JOIN tblProductColors
ON tblColors.ColorID = tblProductColors.ColorID) INNER JOIN tblProducts
ON tblProductColors.ProductID = tblProducts.ProductID WHERE
tblProductColors.ProductID = " & CStr(lngProductID) & " AND ColorName
IS NOT NULL ORDER BY tblProductColors.ProductID,
tblProductColors.SortOrder;"
Set MyDB = CurrentDb
Set ColorRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
If ColorRS.RecordCount > 0 Then
ColorRS.MoveLast
lngColorCount = ColorRS.RecordCount
ColorRS.MoveFirst
For lngI = 1 To lngColorCount
If strTemp = "" Then
strTemp = ColorRS("ColorName")
Else
strTemp = strTemp & ", " & ColorRS("ColorName")
End If
If lngI <> lngColorCount Then ColorRS.MoveNext
Next lngI
End If
ColorRS.Close
Set ColorRS = Nothing
Set MyDB = Nothing
GetProductColors = strTemp
End Function
'-----End Module Code

qryShowProductColors:
SELECT ProductName, SKU, GetProductColors(ProductID) AS Colors FROM
tblProducts ORDER BY ProductName;

!qryShowProductColors:
ProductName SKU Colors
Product1 SKUC NullString
Product2 SKUB Black, Red, Green
Product3 SKUA Blue, Yellow

Use the Variant type instead of the String type if you want the
GetProductColors function to be able to return a Null value. You can
include ProductID in qryShowProductColors if you need it.

I hope this helps,

James A. Fortune
CD********@FortuneJames.com

Dec 16 '05 #2

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

Similar topics

4
by: Arne | last post by:
From: "Arne de Booij" <a_de_booij@hotmail.com> Subject: Comma delimited array into DB problems Date: 9. februar 2004 10:39 Hi, I have an asp page that takes input from a form on the previous...
1
by: ouioui | last post by:
Hi, I need to use the xsl sum function like that : <xsl:value-of select="sum(CompteRendu/Compte/@number)" /> My xml source contains number with comma like that : <Compte number=447,68" ...
4
by: Christine Forber | last post by:
I wonder if anyone knows of some javascript code to check a comma-delimited list of email addresses for basic formating. What I'm looking for is the javascript code to check a form field on form...
2
by: A E | last post by:
Hi, I was wondering if there was a function that handles list elements of a comma delimited list? I need to be able to pass values as a comma delimited list, count the number of values, and...
3
by: dk | last post by:
Hi all, Would appreciate some advice on the following: I am trying to speed up an Access database connected to a SQL Server back-end. I know I can use a pass-through query to pass the sql...
1
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal...
5
by: Yama | last post by:
Hi, I am looking to create a report comma delimited on a click of a button. Explanantion: 1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'" 2. Use either DataReader or...
5
by: SMOlesen | last post by:
Hi I need to split a comma delimited text, however if the comma is between ' ' then no split should occur ie: Class.Value, 'true' , 'some text', 'false', 'text, text, text' should split...
4
by: JustSomeGuy | last post by:
Hi. I have a comma delimited text file that I want to parse. I was going to use fscanf from the C library but as my app is written in C++ I thought I'd use the std io stream library... My Text...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.