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

Concatenate into one field

Hello,

I'm hoping someone might be able to offer some guidance to my problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:

Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D

Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:

10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D

I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.

Thanks in advance,
Aaron
Sep 4 '08 #1
10 7407
Aaron Hoffman wrote:
Hello,

I'm hoping someone might be able to offer some guidance to my problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:

Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D

Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:

10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D

I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.

Thanks in advance,
Aaron
Is there any way you could use a PivotTable/Crosstab query?
Sep 4 '08 #2
On Sep 4, 12:48*pm, Salad <o...@vinegar.comwrote:
Aaron Hoffman wrote:
Hello,
I'm hoping someone might be able to offer some guidance to my problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:
Part_Number * * * *Product_Type
10MC35231 * * * * XYZ1A
10MC35231 * * * * XYZ1B
23XB94142 * * * * *XYZ1A
23XB94142 * * * * *XYZ1B
23XB94142 * * * * *XYZ1C
42PA76251 * * * * *XYZ1D
Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:
10MC35231 * * * * XYZ1A, XYZ1B
23XB94142 * * * * *XYZ1A, XYZ1B, XYZ1C
42PA76251 * * * * *XYZ1D
I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.
Thanks in advance,
Aaron

Is there any way you could use a PivotTable/Crosstab query?- Hide quoted text -

- Show quoted text -
Thanks for your response. Actually I had the same idea. I created a
Crosstab query which gives me the following output with a count for
each appropriate Product_Type.

Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 1 1
23XB94142 1 1 1
42PA76251 1

What I really need is the value of the count to be the Product_Type.

Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 XYZ1A XYZ1B
23XB94142 XYZ1A XYZ1B XYZ1C XYZ1D
42PA76251 XYZ1D

If someone can figure out how I can replace the count with the field
name (Product_Type) then each of the fields could be concatenated
giving the result. I would really like to do this from within Access
and not have to manipulate manually in Excel. I'm not sure if this is
the best approach but I would appreciate any advice.

Thanks,
Aaron
Sep 4 '08 #3
On Sep 4, 11:22*am, Aaron Hoffman <bikefas...@gmail.comwrote:
Hello,

I'm hoping someone might be able to offer some guidance to my problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:

Part_Number * * * *Product_Type
10MC35231 * * * * XYZ1A
10MC35231 * * * * XYZ1B
23XB94142 * * * * *XYZ1A
23XB94142 * * * * *XYZ1B
23XB94142 * * * * *XYZ1C
42PA76251 * * * * *XYZ1D

Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:

10MC35231 * * * * XYZ1A, XYZ1B
23XB94142 * * * * *XYZ1A, XYZ1B, XYZ1C
42PA76251 * * * * *XYZ1D

I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.

Thanks in advance,
Aaron
Here's where I'd use a VBA function to retrieve all the product types
for a given part number and concatenate them all into a comma
delimited string. For example, your initial query would look
something like:

select distinct part_number, sequence_id,
prodtypes_get([sequence_id]) from tblParts

and your VBA function would look something like:

function prodtypes_get(varSeqID as variant) as variant

dim rst as DAO.recordset
dim varRtn as variant

set rst = dbengine(0)(0).openrecordset("select Product_type from
tblProductTypes where Sequence_ID = " & varSeqID)
do until rst.eof
varRtn = varRtn & rst!Product_type & ","
loop

if isnull(varRtn) then
prodtypes_get = varRtn
else
prodtypes_get = left(varRtn,len(varRtn)-1)
end if

end function

You'd probably want to spruce that up with some error handling, etc.
but this is the basic idea.

Bruce
Sep 4 '08 #4
'Fraid you are going to have to use a function.
Air code
Briefly it will look like
Function Concatenate(Part_Number as String) As String

Dim MyDb as database
Dim PartSet as Recordset
dim SQLStg as string
Dim ProductStg as String

SQLStg = "SELECT Part_Number, Product_Type FROM MyQuery " ' This is
the query that joins the 2 tables
SQLStg = SQLStg & "WHERE Part_Number = " & Part_Number & ";"
' That should give a query showing all the Product_Types for that
Part_Number

Set MyDb = CurrentDb
Set PartSet = MyDb.OpenRecordset(SQLStg)
With PartSet
Do Until .EOF
ProductStg = ProductStg & !Product_Type & "," ' Add the
Product_Types and a comma
.MoveNext
Loop
.Close
Set PartSet = Nothing
End With

Concatenate = Left(ProductStg, Len(ProductStg) -1) ' Remove
last Comma

Exit Function

Then in your original query (MyQuery) add a field
P_Types:Concatenate(Part_Number)

HTH

Phil
"Aaron Hoffman" <bi********@gmail.comwrote in message
news:8d**********************************@b30g2000 prf.googlegroups.com...
On Sep 4, 12:48 pm, Salad <o...@vinegar.comwrote:
Aaron Hoffman wrote:
Hello,
I'm hoping someone might be able to offer some guidance to my problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:
Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D
Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:
10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D
I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.
Thanks in advance,
Aaron

Is there any way you could use a PivotTable/Crosstab query?- Hide quoted
text -

- Show quoted text -
Thanks for your response. Actually I had the same idea. I created a
Crosstab query which gives me the following output with a count for
each appropriate Product_Type.

Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 1 1
23XB94142 1 1 1
42PA76251 1

What I really need is the value of the count to be the Product_Type.

Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 XYZ1A XYZ1B
23XB94142 XYZ1A XYZ1B XYZ1C XYZ1D
42PA76251 XYZ1D

If someone can figure out how I can replace the count with the field
name (Product_Type) then each of the fields could be concatenated
giving the result. I would really like to do this from within Access
and not have to manipulate manually in Excel. I'm not sure if this is
the best approach but I would appreciate any advice.

Thanks,
Aaron
Sep 4 '08 #5
On Sep 4, 7:44*pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:
'Fraid you are going to have to use a function.

Air code
Briefly it will look like
Function Concatenate(Part_Number as String) As String

* * Dim MyDb as database
* * Dim PartSet as Recordset
* * dim SQLStg as string
* * Dim ProductStg as String

* * SQLStg = "SELECT Part_Number, Product_Type FROM MyQuery " * *' This is
the query that joins the 2 tables
* * SQLStg = SQLStg & "WHERE Part_Number = " & Part_Number & ";"
' That should give a query showing all the Product_Types for that
Part_Number

* * Set MyDb = CurrentDb
* * Set PartSet = MyDb.OpenRecordset(SQLStg)
* * With PartSet
* * * * Do Until .EOF
* * * * * * ProductStg = ProductStg & !Product_Type & "," * * * *' Add the
Product_Types and a comma
* * * * * * .MoveNext
* * * * Loop
* * * * .Close
* * * * Set PartSet = Nothing
* * End With

* * Concatenate = Left(ProductStg, Len(ProductStg) -1) * * * * * *' Remove
last Comma

Exit Function

Then in your original query (MyQuery) add a field
P_Types:Concatenate(Part_Number)

HTH

Phil"Aaron Hoffman" <bikefas...@gmail.comwrote in message

news:8d**********************************@b30g2000 prf.googlegroups.com...
On Sep 4, 12:48 pm, Salad <o...@vinegar.comwrote:


Aaron Hoffman wrote:
Hello,
I'm hoping someone might be able to offer some guidance to my problem..
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:
Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D
Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:
10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D
I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.
Thanks in advance,
Aaron
Is there any way you could use a PivotTable/Crosstab query?- Hide quoted
text -
- Show quoted text -

Thanks for your response. Actually I had the same idea. I created a
Crosstab query which gives me the following output with a count for
each appropriate Product_Type.

Part_Number * * *XYZ1A * XYZ1B * XYZ1C *XYZ1D
10MC35231 * * * * * 1 * * * * * *1
23XB94142 * * * * * *1 * * * * * *1 * * * * * 1
42PA76251 * * * * * * * * * * * * * * * ** * * * * * * * *1

What I really need is the value of the count to be the Product_Type.

Part_Number * * *XYZ1A * XYZ1B * XYZ1C *XYZ1D
10MC35231 * * * *XYZ1A * XYZ1B
23XB94142 * * * * XYZ1A * XYZ1B * XYZ1C *XYZ1D
42PA76251 * * * * * * * * * * * * * * * ** * * * * * *XYZ1D

If someone can figure out how I can replace the count with the field
name (Product_Type) then each of the fields could be concatenated
giving the result. I would really like to do this from within Access
and not have to manipulate manually in Excel. I'm not sure if this is
the best approach but I would appreciate any advice.

Thanks,
Aaron- Hide quoted text -

- Show quoted text -
I really appreciate your help with this. I'm just not exaclty sure
about when you assign SQLStg the Select statement. My current query
looks like the following:

SELECT tblPart.PART_NUMBER, tblPartModel. PRODUCT_TYPE
FROM tblPartModel INNER JOIN tblPart ON tblPartModel.PART_SEQ_ID =
tblPart.PART_SEQ_ID;
GROUP BY tblPart.PART_NUMBER, tblPartModel.PRODUCT_TYPE;

As you can see i'm joining these two tables by the PART_SEQ_ID and
then using group by to get only the unique records. Do I simply use my
exisiting query and replace MyQuery in your code with my table name?
Are there any changes that need to be made to this query?

I went ahead and added P_Types:Concatenate(Part_Number) into my
existing query and attempted to see the Datasheet View. I then
recieved a compile error saying, "Only comments may appear after End
Sub, End Function, or End Property." Thinking that the comments were
causing a problem, I removed them all from the code but this did not
fix the problem. Any assistance getting this to work would be greatly
appreciated.

Thanks for the help,
Aaron
Sep 5 '08 #6
Ok Aaron Lets take it step by step

save
SELECT tblPart.PART_NUMBER, tblPartModel. PRODUCT_TYPE
FROM tblPartModel INNER JOIN tblPart ON tblPartModel.PART_SEQ_ID =
tblPart.PART_SEQ_ID;
GROUP BY tblPart.PART_NUMBER, tblPartModel.PRODUCT_TYPE;

as My query. Can you see it in query design and does ir run OK

Phil
________________________-
"Aaron Hoffman" <bi********@gmail.comwrote in message
news:d6**********************************@l43g2000 hsh.googlegroups.com...
On Sep 4, 7:44 pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:
'Fraid you are going to have to use a function.

Air code
Briefly it will look like
Function Concatenate(Part_Number as String) As String

Dim MyDb as database
Dim PartSet as Recordset
dim SQLStg as string
Dim ProductStg as String

SQLStg = "SELECT Part_Number, Product_Type FROM MyQuery " ' This is
the query that joins the 2 tables
SQLStg = SQLStg & "WHERE Part_Number = " & Part_Number & ";"
' That should give a query showing all the Product_Types for that
Part_Number

Set MyDb = CurrentDb
Set PartSet = MyDb.OpenRecordset(SQLStg)
With PartSet
Do Until .EOF
ProductStg = ProductStg & !Product_Type & "," ' Add the
Product_Types and a comma
.MoveNext
Loop
.Close
Set PartSet = Nothing
End With

Concatenate = Left(ProductStg, Len(ProductStg) -1) ' Remove
last Comma

Exit Function

Then in your original query (MyQuery) add a field
P_Types:Concatenate(Part_Number)

HTH

Phil"Aaron Hoffman" <bikefas...@gmail.comwrote in message

news:8d**********************************@b30g2000 prf.googlegroups.com...
On Sep 4, 12:48 pm, Salad <o...@vinegar.comwrote:


Aaron Hoffman wrote:
Hello,
I'm hoping someone might be able to offer some guidance to my problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:
Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D
Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:
10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D
I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.
Thanks in advance,
Aaron
Is there any way you could use a PivotTable/Crosstab query?- Hide quoted
text -
- Show quoted text -

Thanks for your response. Actually I had the same idea. I created a
Crosstab query which gives me the following output with a count for
each appropriate Product_Type.

Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 1 1
23XB94142 1 1 1
42PA76251 1

What I really need is the value of the count to be the Product_Type.

Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 XYZ1A XYZ1B
23XB94142 XYZ1A XYZ1B XYZ1C XYZ1D
42PA76251 XYZ1D

If someone can figure out how I can replace the count with the field
name (Product_Type) then each of the fields could be concatenated
giving the result. I would really like to do this from within Access
and not have to manipulate manually in Excel. I'm not sure if this is
the best approach but I would appreciate any advice.

Thanks,
Aaron- Hide quoted text -

- Show quoted text -
I really appreciate your help with this. I'm just not exaclty sure
about when you assign SQLStg the Select statement. My current query
looks like the following:

SELECT tblPart.PART_NUMBER, tblPartModel. PRODUCT_TYPE
FROM tblPartModel INNER JOIN tblPart ON tblPartModel.PART_SEQ_ID =
tblPart.PART_SEQ_ID;
GROUP BY tblPart.PART_NUMBER, tblPartModel.PRODUCT_TYPE;

As you can see i'm joining these two tables by the PART_SEQ_ID and
then using group by to get only the unique records. Do I simply use my
exisiting query and replace MyQuery in your code with my table name?
Are there any changes that need to be made to this query?

I went ahead and added P_Types:Concatenate(Part_Number) into my
existing query and attempted to see the Datasheet View. I then
recieved a compile error saying, "Only comments may appear after End
Sub, End Function, or End Property." Thinking that the comments were
causing a problem, I removed them all from the code but this did not
fix the problem. Any assistance getting this to work would be greatly
appreciated.

Thanks for the help,
Aaron
Sep 5 '08 #7
Sorry, the last line should be "End Function", not "Exit Function"

Phil

"Aaron Hoffman" <bi********@gmail.comwrote in message
news:d6**********************************@l43g2000 hsh.googlegroups.com...
On Sep 4, 7:44 pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:
'Fraid you are going to have to use a function.

Air code
Briefly it will look like
Function Concatenate(Part_Number as String) As String

Dim MyDb as database
Dim PartSet as Recordset
dim SQLStg as string
Dim ProductStg as String

SQLStg = "SELECT Part_Number, Product_Type FROM MyQuery " ' This is
the query that joins the 2 tables
SQLStg = SQLStg & "WHERE Part_Number = " & Part_Number & ";"
' That should give a query showing all the Product_Types for that
Part_Number

Set MyDb = CurrentDb
Set PartSet = MyDb.OpenRecordset(SQLStg)
With PartSet
Do Until .EOF
ProductStg = ProductStg & !Product_Type & "," ' Add the
Product_Types and a comma
.MoveNext
Loop
.Close
Set PartSet = Nothing
End With

Concatenate = Left(ProductStg, Len(ProductStg) -1) ' Remove
last Comma

Exit Function

Then in your original query (MyQuery) add a field
P_Types:Concatenate(Part_Number)

HTH

Phil"Aaron Hoffman" <bikefas...@gmail.comwrote in message

news:8d**********************************@b30g2000 prf.googlegroups.com...
On Sep 4, 12:48 pm, Salad <o...@vinegar.comwrote:


Aaron Hoffman wrote:
Hello,
I'm hoping someone might be able to offer some guidance to my problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:
Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D
Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:
10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D
I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.
Thanks in advance,
Aaron
Is there any way you could use a PivotTable/Crosstab query?- Hide quoted
text -
- Show quoted text -

Thanks for your response. Actually I had the same idea. I created a
Crosstab query which gives me the following output with a count for
each appropriate Product_Type.

Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 1 1
23XB94142 1 1 1
42PA76251 1

What I really need is the value of the count to be the Product_Type.

Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 XYZ1A XYZ1B
23XB94142 XYZ1A XYZ1B XYZ1C XYZ1D
42PA76251 XYZ1D

If someone can figure out how I can replace the count with the field
name (Product_Type) then each of the fields could be concatenated
giving the result. I would really like to do this from within Access
and not have to manipulate manually in Excel. I'm not sure if this is
the best approach but I would appreciate any advice.

Thanks,
Aaron- Hide quoted text -

- Show quoted text -
I really appreciate your help with this. I'm just not exaclty sure
about when you assign SQLStg the Select statement. My current query
looks like the following:

SELECT tblPart.PART_NUMBER, tblPartModel. PRODUCT_TYPE
FROM tblPartModel INNER JOIN tblPart ON tblPartModel.PART_SEQ_ID =
tblPart.PART_SEQ_ID;
GROUP BY tblPart.PART_NUMBER, tblPartModel.PRODUCT_TYPE;

As you can see i'm joining these two tables by the PART_SEQ_ID and
then using group by to get only the unique records. Do I simply use my
exisiting query and replace MyQuery in your code with my table name?
Are there any changes that need to be made to this query?

I went ahead and added P_Types:Concatenate(Part_Number) into my
existing query and attempted to see the Datasheet View. I then
recieved a compile error saying, "Only comments may appear after End
Sub, End Function, or End Property." Thinking that the comments were
causing a problem, I removed them all from the code but this did not
fix the problem. Any assistance getting this to work would be greatly
appreciated.

Thanks for the help,
Aaron
Sep 5 '08 #8
On Sep 5, 12:24*pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:
Sorry, the last line should be "End Function", not "Exit Function"

Phil

"Aaron Hoffman" <bikefas...@gmail.comwrote in message

news:d6**********************************@l43g2000 hsh.googlegroups.com...
On Sep 4, 7:44 pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:


'Fraid you are going to have to use a function.
Air code
Briefly it will look like
Function Concatenate(Part_Number as String) As String
Dim MyDb as database
Dim PartSet as Recordset
dim SQLStg as string
Dim ProductStg as String
SQLStg = "SELECT Part_Number, Product_Type FROM MyQuery " ' This is
the query that joins the 2 tables
SQLStg = SQLStg & "WHERE Part_Number = " & Part_Number & ";"
' That should give a query showing all the Product_Types for that
Part_Number
Set MyDb = CurrentDb
Set PartSet = MyDb.OpenRecordset(SQLStg)
With PartSet
Do Until .EOF
ProductStg = ProductStg & !Product_Type & "," ' Add the
Product_Types and a comma
.MoveNext
Loop
.Close
Set PartSet = Nothing
End With
Concatenate = Left(ProductStg, Len(ProductStg) -1) ' Remove
last Comma
Exit Function
Then in your original query (MyQuery) add a field
P_Types:Concatenate(Part_Number)
HTH
Phil"Aaron Hoffman" <bikefas...@gmail.comwrote in message
news:8d**********************************@b30g2000 prf.googlegroups.com....
On Sep 4, 12:48 pm, Salad <o...@vinegar.comwrote:
Aaron Hoffman wrote:
Hello,
I'm hoping someone might be able to offer some guidance to my problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you can
see some sample data:
Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D
Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:
10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D
I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone could
help give me a direction with this.
Thanks in advance,
Aaron
Is there any way you could use a PivotTable/Crosstab query?- Hide quoted
text -
- Show quoted text -
Thanks for your response. Actually I had the same idea. I created a
Crosstab query which gives me the following output with a count for
each appropriate Product_Type.
Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 1 1
23XB94142 1 1 1
42PA76251 1
What I really need is the value of the count to be the Product_Type.
Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 XYZ1A XYZ1B
23XB94142 XYZ1A XYZ1B XYZ1C XYZ1D
42PA76251 XYZ1D
If someone can figure out how I can replace the count with the field
name (Product_Type) then each of the fields could be concatenated
giving the result. I would really like to do this from within Access
and not have to manipulate manually in Excel. I'm not sure if this is
the best approach but I would appreciate any advice.
Thanks,
Aaron- Hide quoted text -
- Show quoted text -

I really appreciate your help with this. I'm just not exaclty sure
about when you assign SQLStg the Select statement. My current query
looks like the following:

SELECT tblPart.PART_NUMBER, tblPartModel. PRODUCT_TYPE
FROM tblPartModel INNER JOIN tblPart ON tblPartModel.PART_SEQ_ID =
tblPart.PART_SEQ_ID;
GROUP BY tblPart.PART_NUMBER, tblPartModel.PRODUCT_TYPE;

As you can see i'm joining these two tables by the PART_SEQ_ID and
then using group by to get only the unique records. Do I simply use my
exisiting query and replace MyQuery in your code with my table name?
Are there any changes that need to be made to this query?

I went ahead and added P_Types:Concatenate(Part_Number) into my
existing query and attempted to see the Datasheet View. I then
recieved a compile error saying, "Only comments may appear after End
Sub, End Function, or End Property." Thinking that the comments were
causing a problem, I removed them all from the code but this did not
fix the problem. Any assistance getting this to work would be greatly
appreciated.

Thanks for the help,
Aaron- Hide quoted text -

- Show quoted text -
Ok, I changed the last line to "End Function."

The query runs fine before I put "P_Types:Concatenate(Part_Number)"
into the query. Once I try to view the Datasheet, I still get the same
compile error. What am I doing wrong?
Sep 5 '08 #9
Ok If the query is OK then the problem is in the function

I presume this is saved in Module1 (or some other name)

Have you compiled it as this should show the errors.

What version of Access are you using?

Phil

"Aaron Hoffman" <bi********@gmail.comwrote in message
news:6c**********************************@p25g2000 hsf.googlegroups.com...
On Sep 5, 12:24 pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:
Sorry, the last line should be "End Function", not "Exit Function"

Phil

"Aaron Hoffman" <bikefas...@gmail.comwrote in message

news:d6**********************************@l43g2000 hsh.googlegroups.com...
On Sep 4, 7:44 pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:


'Fraid you are going to have to use a function.
Air code
Briefly it will look like
Function Concatenate(Part_Number as String) As String
Dim MyDb as database
Dim PartSet as Recordset
dim SQLStg as string
Dim ProductStg as String
SQLStg = "SELECT Part_Number, Product_Type FROM MyQuery " ' This is
the query that joins the 2 tables
SQLStg = SQLStg & "WHERE Part_Number = " & Part_Number & ";"
' That should give a query showing all the Product_Types for that
Part_Number
Set MyDb = CurrentDb
Set PartSet = MyDb.OpenRecordset(SQLStg)
With PartSet
Do Until .EOF
ProductStg = ProductStg & !Product_Type & "," ' Add the
Product_Types and a comma
.MoveNext
Loop
.Close
Set PartSet = Nothing
End With
Concatenate = Left(ProductStg, Len(ProductStg) -1) ' Remove
last Comma
Exit Function
Then in your original query (MyQuery) add a field
P_Types:Concatenate(Part_Number)
HTH
Phil"Aaron Hoffman" <bikefas...@gmail.comwrote in message
news:8d**********************************@b30g2000 prf.googlegroups.com...
On Sep 4, 12:48 pm, Salad <o...@vinegar.comwrote:
Aaron Hoffman wrote:
Hello,
I'm hoping someone might be able to offer some guidance to my
problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you
can
see some sample data:
Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D
Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:
10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D
I found a few concatenate functions but it seemed that the either it
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone
could
help give me a direction with this.
Thanks in advance,
Aaron
Is there any way you could use a PivotTable/Crosstab query?- Hide
quoted
text -
- Show quoted text -
Thanks for your response. Actually I had the same idea. I created a
Crosstab query which gives me the following output with a count for
each appropriate Product_Type.
Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 1 1
23XB94142 1 1 1
42PA76251 1
What I really need is the value of the count to be the Product_Type.
Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 XYZ1A XYZ1B
23XB94142 XYZ1A XYZ1B XYZ1C XYZ1D
42PA76251 XYZ1D
If someone can figure out how I can replace the count with the field
name (Product_Type) then each of the fields could be concatenated
giving the result. I would really like to do this from within Access
and not have to manipulate manually in Excel. I'm not sure if this is
the best approach but I would appreciate any advice.
Thanks,
Aaron- Hide quoted text -
- Show quoted text -

I really appreciate your help with this. I'm just not exaclty sure
about when you assign SQLStg the Select statement. My current query
looks like the following:

SELECT tblPart.PART_NUMBER, tblPartModel. PRODUCT_TYPE
FROM tblPartModel INNER JOIN tblPart ON tblPartModel.PART_SEQ_ID =
tblPart.PART_SEQ_ID;
GROUP BY tblPart.PART_NUMBER, tblPartModel.PRODUCT_TYPE;

As you can see i'm joining these two tables by the PART_SEQ_ID and
then using group by to get only the unique records. Do I simply use my
exisiting query and replace MyQuery in your code with my table name?
Are there any changes that need to be made to this query?

I went ahead and added P_Types:Concatenate(Part_Number) into my
existing query and attempted to see the Datasheet View. I then
recieved a compile error saying, "Only comments may appear after End
Sub, End Function, or End Property." Thinking that the comments were
causing a problem, I removed them all from the code but this did not
fix the problem. Any assistance getting this to work would be greatly
appreciated.

Thanks for the help,
Aaron- Hide quoted text -

- Show quoted text -
Ok, I changed the last line to "End Function."

The query runs fine before I put "P_Types:Concatenate(Part_Number)"
into the query. Once I try to view the Datasheet, I still get the same
compile error. What am I doing wrong?
Sep 5 '08 #10
On Sep 5, 2:36*pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:
Ok If the query is OK then the problem is in the function

I presume this is saved in Module1 (or some other name)

Have you compiled it as this should show the errors.

What version of Access are you using?

Phil

"Aaron Hoffman" <bikefas...@gmail.comwrote in message

news:6c**********************************@p25g2000 hsf.googlegroups.com...
On Sep 5, 12:24 pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:


Sorry, the last line should be "End Function", not "Exit Function"
Phil
"Aaron Hoffman" <bikefas...@gmail.comwrote in message
news:d6**********************************@l43g2000 hsh.googlegroups.com....
On Sep 4, 7:44 pm, "Phil Stanton" <p...@myfamilyname.co.ukwrote:
'Fraid you are going to have to use a function.
Air code
Briefly it will look like
Function Concatenate(Part_Number as String) As String
Dim MyDb as database
Dim PartSet as Recordset
dim SQLStg as string
Dim ProductStg as String
SQLStg = "SELECT Part_Number, Product_Type FROM MyQuery " ' This is
the query that joins the 2 tables
SQLStg = SQLStg & "WHERE Part_Number = " & Part_Number & ";"
' That should give a query showing all the Product_Types for that
Part_Number
Set MyDb = CurrentDb
Set PartSet = MyDb.OpenRecordset(SQLStg)
With PartSet
Do Until .EOF
ProductStg = ProductStg & !Product_Type & "," ' Add the
Product_Types and a comma
.MoveNext
Loop
.Close
Set PartSet = Nothing
End With
Concatenate = Left(ProductStg, Len(ProductStg) -1) ' Remove
last Comma
Exit Function
Then in your original query (MyQuery) add a field
P_Types:Concatenate(Part_Number)
HTH
Phil"Aaron Hoffman" <bikefas...@gmail.comwrote in message
>news:8d**********************************@b30g200 0prf.googlegroups.com....
On Sep 4, 12:48 pm, Salad <o...@vinegar.comwrote:
Aaron Hoffman wrote:
Hello,
I'm hoping someone might be able to offer some guidance to my
problem.
I have one query in MS Access which consists of 2 tables joined by a
SEQUENCE_ID. By joining the two tables I am able to produce a query
that gives me two fields, Part_Number and Product_Type. Below you
can
see some sample data:
Part_Number Product_Type
10MC35231 XYZ1A
10MC35231 XYZ1B
23XB94142 XYZ1A
23XB94142 XYZ1B
23XB94142 XYZ1C
42PA76251 XYZ1D
Ideally, it would be nice for the query to have an additional field
which would concatenate the Product_Type's:
10MC35231 XYZ1A, XYZ1B
23XB94142 XYZ1A, XYZ1B, XYZ1C
42PA76251 XYZ1D
I found a few concatenate functions but it seemed that the eitherit
did not like that I was joining two tables in the query or that the
data was in only one table. I would really appreciate if someone
could
help give me a direction with this.
Thanks in advance,
Aaron
Is there any way you could use a PivotTable/Crosstab query?- Hide
quoted
text -
- Show quoted text -
Thanks for your response. Actually I had the same idea. I created a
Crosstab query which gives me the following output with a count for
each appropriate Product_Type.
Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 1 1
23XB94142 1 1 1
42PA76251 1
What I really need is the value of the count to be the Product_Type.
Part_Number XYZ1A XYZ1B XYZ1C XYZ1D
10MC35231 XYZ1A XYZ1B
23XB94142 XYZ1A XYZ1B XYZ1C XYZ1D
42PA76251 XYZ1D
If someone can figure out how I can replace the count with the field
name (Product_Type) then each of the fields could be concatenated
giving the result. I would really like to do this from within Access
and not have to manipulate manually in Excel. I'm not sure if this is
the best approach but I would appreciate any advice.
Thanks,
Aaron- Hide quoted text -
- Show quoted text -
I really appreciate your help with this. I'm just not exaclty sure
about when you assign SQLStg the Select statement. My current query
looks like the following:
SELECT tblPart.PART_NUMBER, tblPartModel. PRODUCT_TYPE
FROM tblPartModel INNER JOIN tblPart ON tblPartModel.PART_SEQ_ID =
tblPart.PART_SEQ_ID;
GROUP BY tblPart.PART_NUMBER, tblPartModel.PRODUCT_TYPE;
As you can see i'm joining these two tables by the PART_SEQ_ID and
then using group by to get only the unique records. Do I simply use my
exisiting query and replace MyQuery in your code with my table name?
Are there any changes that need to be made to this query?
I went ahead and added P_Types:Concatenate(Part_Number) into my
existing query and attempted to see the Datasheet View. I then
recieved a compile error saying, "Only comments may appear after End
Sub, End Function, or End Property." Thinking that the comments were
causing a problem, I removed them all from the code but this did not
fix the problem. Any assistance getting this to work would be greatly
appreciated.
Thanks for the help,
Aaron- Hide quoted text -
- Show quoted text -

Ok, I changed the last line to "End Function."

The query runs fine before I put "P_Types:Concatenate(Part_Number)"
into the query. Once I try to view the Datasheet, I still get the same
compile error. What am I doing wrong?- Hide quoted text -

- Show quoted text -

That is correct. It is saved as Module1.

When I try to compile all it says is "Compile error: Only comments may
appear after End Sub, End Function, or End Property."

I'm using Access 2000 (9.0.8968 SP-3).

I don't know if this matters but like I said the Query works fine
without "P_Types: Concatenate([Part_Number])". When I add this into
field in the Query Design view it automatically makes it "Group By"
because the other fields (PART_NUMBER) and (PRODUCT_TYPE) are grouped.
I thought I would mention this in the event that it is causing
problems.

Thanks,
Aaron
Sep 5 '08 #11

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

Similar topics

2
by: Mark | last post by:
I am trying to populate a field in a SQL table based on the values returned from using substring on a text field. Example: Field Name = RecNum Field Value = 024071023 The 7th and 8th...
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
4
by: Onion | last post by:
This has to be simple, but I'm forced to admit that I'm a novice who can't figure it out. I have a listbox in a form that allows multiple selections. That works fine. The problem: I can't...
8
by: Dixie | last post by:
I have the results of a query to send to a mailmerge with Word 2000. The query produces say 6 to 8 records, where only 1 of the fields is different from record to record. I can only have one...
2
by: exapplerep | last post by:
I've seen how to use VBA code to concatenate two fields into a third by using an expression in the "After Update" property in fields 1 & 2. field3 = field1 + field2 The above code would go...
4
by: Dan | last post by:
Hi all, I am creating a search table where the keywords field is made up of several text fields and this is causing me some problems. I can concatentate the text ok but i can't seem to concatenate...
4
by: mattdoughty | last post by:
Hi Forum, I'm trying to perform a type of concatenate function on a table and am not really sure where to start. I'd like to aggregate the values from 'field' on their ID. To explain, my table is...
5
by: Dean | last post by:
Hi, I have a table with non-unique identifiers. I need to take all the values with the same ID's and combine them into one field with a semicolon as a seperator. These values may exceed 255...
5
TheSmileyCoder
by: TheSmileyCoder | last post by:
I was trying to look at this post Summing Fields if not null and to test it I created an unbound form, with 4 unbound text fields, and a calculated field, with the control...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.