 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 14th, 2008, 10:33 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
concatenating records
Hi,
I have the below data.
Col1 Col2 Col3 Col4 Col5
------------------------------------------------
CompA Sales Dept UK
CompA Sales Dept USA
CompA Sales Dept Asia
CompB HR Dept USA
CompB HR Dept UK
------------------------------------------------
I am trying to concatenate the above records to get the below result.
Can I use the concatenation function in a query somehow ? Can somebody please point me in the right direction.
------------------------------------------------
CompA Sales Dept USA UK Asia
CompB HR Dept USA, UK
------------------------------------------------
Thanks
|
|

October 15th, 2008, 07:59 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can somebody please guide me on how to do it.
Thanks
|
|

October 15th, 2008, 02:15 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Wow, this shows up a lot. This is the result of improper table / relationship design. I have done this with code if you are interested in that solution.
mmcdonal
Look it up at: http://wrox.books24x7.com
|
|

October 15th, 2008, 03:45 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
This data is not directly from a table. This is a query result from various tables. And I am not able to get it in the format I want (basically one row for one company).
Is there a way of querying to get it directly in the required format.
Thanks
|
|

October 16th, 2008, 06:30 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
You will need to post the table structure. Show some sample data in each table.
mmcdonal
Look it up at: http://wrox.books24x7.com
|
|

October 16th, 2008, 02:23 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi mmcdonal,
Is there a function to concatenate data from all fields without having to specify the actual field name ?
Thanks
|
|

October 16th, 2008, 02:25 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
You can write code to refer to columns in recordsets as Column 0, Column 1, etc. It is sometimes easier to use actual column names. But without knowing what the underlying data structure is, there is no way to write code or queries to concatenate this the way you want.
mmcdonal
Look it up at: http://wrox.books24x7.com
|
|

November 5th, 2008, 12:43 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here's some code I sometimes use to work with tables:
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
With db.TableDefs(SourceTable)
For i = 0 To .Fields.Count - 1
fieldName(i) = .Fields(i).Name
Next i
End With
You can then reference the fields like this:
rs(fieldName(i))
-Phil-
|
|

November 5th, 2008, 05:52 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Pardon me, but that's silly.
There will be *NO DIFFERENCE* between
rs(fieldName(i))
and simply (and faster)
rs(i)
What's the point?
|
|

November 6th, 2008, 05:07 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Certainly I am suitably chastised for my silliness. Obviously there can be no reason for having a table's field names stored in an array.
-Phil-
|
|
 |