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

Combining Multiple Rows of one Field into One Result

I realize the thread I am responding to was posted in January but I am basically having the same issue. I am not familiar with VBA but use Access daily. I have written simple scripts but nothing to write home about. I followed the previous thread and my situation is very similar.

I have an application with users. These users have access to multiple terminals. I am trying to combine the TerminalName field with all terminals the user has access to:

User Terminals
John Doe 121,65,307
Jane Doe 121

etc.

I pasted the module:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. 'Concat Returns Products
  3. 'listed by company
  4. Public Function Concat(strPartyName As String, _
  5.                        strTerminalName As String) As String
  6.     Static strLastPartyName As String
  7.     Static strTerminals As String
  8.  
  9.     If strPartyName = strLastPartyName Then
  10.         strTerminals = strTerminals & ", " & strTerminalName
  11.     Else
  12.         strLastPartyName = strPartyName
  13.         strTerminals = strTerminalName
  14.     End If
  15.     Concat = strTerminals
  16. End Function
  17.  
and my sql query is:

Expand|Select|Wrap|Line Numbers
  1. SELECT [Assigned Terminals Export].PartyName, [Assigned Terminals Export].TerminalName, Last(Concat([PartyName],[TerminalName])) AS Terminals
  2. FROM [Assigned Terminals Export]
  3. GROUP BY [Assigned Terminals Export].PartyName, [Assigned Terminals Export].TerminalName;
  4.  
When I try to run the query I get:
Undefined function 'Concat' in expression.

Can you please help me?
Oct 3 '07 #1
14 2593
Scott Price
1,384 Expert 1GB
Link to previous thread: http://www.thescripts.com/forum/showthread.php?t=589999

JackieFM:

You have asked your question in another member's thread. This is called thread hijacking and is not allowed on this site. There are various reasons for this, the principal of which is that it typically diverts the flow of the thread away from his needs and into yours. Another is that it will tend to mean that your new question is not seen as such, and may get overlooked by many of our experts (You appreciate that they're not looking for answered questions).
Please post your questions in their own threads in future (See How to Ask a Question ).

I have split the thread into two, and your question now has it's own thread.

MODERATOR.
Oct 3 '07 #2
Scott Price
1,384 Expert 1GB
The function code needs to go into a standard code module. Create one in the vba editor window by clicking on the Insert Menu, then Module.

This should help!

Regards, and welcome to the Scripts.

Scott
Oct 3 '07 #3
I have added it as a module but it still gives me the same error. Is there something else I am supposed to do?
Oct 3 '07 #4
I realize the thread I am responding to was posted in January but I am basically having the same issue. I am not familiar with VBA but use Access daily. I have written simple scripts but nothing to write home about. I followed the previous thread and my situation is very similar.

I have an application with users. These users have access to multiple terminals. I am trying to combine the TerminalName field with all terminals the user has access to:

User Terminals
John Doe 121,65,307
Jane Doe 121

etc.

I pasted the module:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. 'Concat Returns Products
  3. 'listed by company
  4. Public Function Concat(strPartyName As String, _
  5.                        strTerminalName As String) As String
  6.     Static strLastPartyName As String
  7.     Static strTerminals As String
  8.  
  9.     If strPartyName = strLastPartyName Then
  10.         strTerminals = strTerminals & ", " & strTerminalName
  11.     Else
  12.         strLastPartyName = strPartyName
  13.         strTerminals = strTerminalName
  14.     End If
  15.     Concat = strTerminals
  16. End Function
  17.  
and my sql query is:

Expand|Select|Wrap|Line Numbers
  1. SELECT [Assigned Terminals Export].PartyName, [Assigned Terminals Export].TerminalName, Last(Concat([PartyName],[TerminalName])) AS Terminals
  2. FROM [Assigned Terminals Export]
  3. GROUP BY [Assigned Terminals Export].PartyName, [Assigned Terminals Export].TerminalName;
  4.  
When I try to run the query I get:
Undefined function 'Concat' in expression.

Can you please help me?
In line 10 of your code:
strTerminals = strTerminals & ", " & strTerminalName
I take it the message comes up and it doesn't like the comma (which is in red)? It may be looking for a replace function when you use a comma. Try a space or a semicolon...
Oct 3 '07 #5
Unfortunately that did not help. Is there a reference I need to add maybe? I currently have:

Visual Basic for Applications
Microsoft Access 11.0 Object Library
OLE Automation
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Objects 2.5 Library
Oct 3 '07 #6
Scott Price
1,384 Expert 1GB
The error message: "Undefined function Concat" is indicating that you haven't properly placed the function! For some reason, vba hasn't yet recognized that this function does indeed exist.

Are you sure that you placed this into a Module, and not a Class Module?
Have you also done a Debug>Compile, and Save?

Regards,
Scott
Oct 3 '07 #7
Scott Price
1,384 Expert 1GB
I just copied and pasted your code into a fresh code module, clicked the Debug menu, Compile, then Save.

Tried it in a fresh query in my test database and it works just fine.

Your references look fine to me as well. If you still are having problems, we'll have to look a little bit closer at them, but otherwise...

Regards,
Scott
Oct 3 '07 #8
I can only apologize for the missing the most obvious. I neglected to remove the underscore in the module after I pasted it. Once I removed the underscore, complied and saved it worked like a charm.

Thank you, Thank you
Oct 3 '07 #9
I do however have one other problem. The field size is limited to 255 char. Can that be changed. Each terminal is 3 characters long, with the space and comma I am limited to 51 terminals can be combined to this field. Some users have access to over 700 terminals.
Oct 3 '07 #10
Scott Price
1,384 Expert 1GB
I do however have one other problem. The field size is limited to 255 char. Can that be changed. Each terminal is 3 characters long, with the space and comma I am limited to 51 terminals can be combined to this field. Some users have access to over 700 terminals.
Try changing the table field specification to Memo data type. The standard Text data type restricts to the 255 characters like you mention.

Glad you got it working!

Regards,
Scott
Oct 3 '07 #11
I believe it is using the default text format which is limited to the 255 char. It is a new field created through the query. Is there a way to change it in the sql? The field is:

Last(Concat([PartyName],[TerminalName])) AS Terminals

This field was created in the query. I have changed both TerminalName and PartyName to Memo fields with no success.
Oct 4 '07 #12
Scott Price
1,384 Expert 1GB
Hi Jackie,

Apparently you are suffering from the aggregate function Group By and probably Last() in your query. Have a look at this link to Allen Browne's tip sheet about Truncation of Memo Fields

Regards,
Scott
Oct 4 '07 #13
Unfortunately I followed all "rules" to prevent this issue but still seem to be unable to resolve it. Below is my query. There is not formatting in query or table, no grouping on TerminalName, any suggestions?

SELECT [Assigned Terminals Export].PartyID, [Assigned Terminals Export].PartyName, Last(Concat([PartyName],[TerminalName])) AS Terminals
FROM [Assigned Terminals Export]
GROUP BY [Assigned Terminals Export].PartyID, [Assigned Terminals Export].PartyName
ORDER BY [Assigned Terminals Export].PartyName;
Oct 4 '07 #14
Scott Price
1,384 Expert 1GB
I would strip it down to the basic Concat() function query, then use that to update a table. From there you can run it through another query to do the grouping.

In other words:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Assigned Terminals Export].PartyID, [Assigned Terminals Export].PartyName, Last(Concat([PartyName],[TerminalName])) AS Terminals
  2. FROM [Assigned Terminals Export];
Regards,
Scott
Oct 4 '07 #15

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

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
4
by: Omey Samaroo | last post by:
Dear Access Gurus, Can anyone provide me with some much needed assistance. I would like to combine the contents of 3 text fields into one field. Can someone provide some code or a method to do...
2
by: Will | last post by:
I have a table, tblManinstructions with fields Code & InstructionID, one Code can have many InstructionID. I also have tblinstructions (fields instructionID & instruction). What I want to do is...
2
by: ameshkin | last post by:
I know this is probably not too hard to do, but how do I display multiple rows of a mysql query/recordset. Im having trouble doing this. I don't just want to display them, but I want to make sure...
46
by: kyjabber | last post by:
I have a multi relationship database and I'm pulling the company's contact info, queryied if they are a grower, and a resulting list of their products by catgeory. I need to have the products listed...
2
by: rpeacock | last post by:
I have a function that takes a field with values separated by commas within the field and splits them to multiple rows. Example: Field - Interior Value - abc,def,efg,ghi Output: ID Item 1 ...
1
by: assgar | last post by:
Hi I was using a schroll bar to display multiple rows of dynamically created from database records. The scrolling was not displaying the data properly so I have decided to use pagination. The...
5
by: MARIEDB2 | last post by:
Hello, I am struggling to build a query on a DB2 db wich does an update for multiple fields which are the result of a select query with where clause (using multiple tables in the condition). ...
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?
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
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
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,...

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.