By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

Procedure Name Same as Module Name

P: 20
Admin: This thread was moved from a hijack question posted in Combining Rows-Opposite of Union. Please do not post new questions in existing threads.

@NeoPa

Created a Bytes account to tell you this work is still helping people in 2019!

This Concat function (the one marked as solution) was exactly what I was looking for. Function worked perfectly yesterday. However, today I'm getting an error "Undefined Function 'Concat' In Expression" with no change in my code. I created a new module and changed Concat to Concat2 and it worked. I'm new to VBA and would love to know how to avoid this in the future.

Also, does this work when using a query or subquery in the FROM clause? For me, this yields no concatenation, but creating a table from the same query and referencing that works. Any advice would be great.
Jan 4 '19 #1

✓ answered by twinnyfo

Barmaximus,

Welcome to Bytes!

However, today I'm getting an error "Undefined Function 'Concat' In Expression" with no change in my code.
Any chance that you named the Module "Concat"? This would cause some ambiguity within the DB.

Share this Question
Share on Google+
15 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,184
Barmaximus,

Welcome to Bytes!

However, today I'm getting an error "Undefined Function 'Concat' In Expression" with no change in my code.
Any chance that you named the Module "Concat"? This would cause some ambiguity within the DB.
Jan 4 '19 #2

P: 20
@twinnyfo of course I did. Changing the name of the module fixed this. Any thoughts on why it worked fine previously?
Jan 4 '19 #3

twinnyfo
Expert Mod 2.5K+
P: 3,184
You probably tried using it prior to saving the Module's Name.

When you call Concat and you have a Module named Concat and a Procedure with the same name, the DB doesn't know how to properly disambiguate. When you build the procedure, your Module was named "Module1" by default--so there was no issue.

These types of issues have had me scratching my head for hours in the past. Now I know to use better naming conventions. So, I would have saved the Module as "modConcat", which contained a Procedure named "Concat". Some go further and name Functions "fnConcat" to further prevent any disambiguation.

Hope this hepps!

Let us know if there are any other headscratchers you need hepp with!
Jan 4 '19 #4

P: 20
Thanks @twinnyfo . Any thoughts on this function not yielding a concatenation when called in a Select query with a sub Select query in the From clause? I'm trying to use the function on data generated from a query. However, it doesn't yield the desired results unless I create a table that is identical to the query output.
Jan 4 '19 #5

twinnyfo
Expert Mod 2.5K+
P: 3,184
My only thought is that the SQL engine gets confused or overwhelmed when going into the subqueries. For example, you can refer to open forms for criteria in your queries, but you can't refer to open forms when the criteria is in a subquery (if I remember my experiences correctly).

What have you been trying? If you post your SQL, we can take a look and see if we can decipher anything.
Jan 4 '19 #6

P: 20
Below is my code. The subquery finds all keyword matches from a reference library [Component Library] to [Data - Inventory].Description and returns the keyword found and the associated Type. This yields more than one row per component where multiple matches are found. Works perfectly as a standalone query. When inserted as a subquery, it yields one match per component, no concatenation. However, when I create a table identical to the results of the query, I can achieve the desired concatenation.

Expand|Select|Wrap|Line Numbers
  1. SELECT x.Component, 
  2.        Max(x.Description), 
  3.        Max(Concat(Nz(x.Component), Nz(x.PartType)))
  4. FROM (SELECT [Data - Inventory].Component, 
  5.              [Data - Inventory].Description, 
  6.              [Component Library].Keyword AS [Key], 
  7.              [Component Library].Type AS PartType
  8.       FROM [Component Library] 
  9.       LEFT JOIN [Data - Inventory] 
  10.       ON [Data - Inventory].Description LIKE "*" &  [Component Library].Keyword & "*") 
  11.       AS x
  12. GROUP BY x.Component;
Jan 4 '19 #7

twinnyfo
Expert Mod 2.5K+
P: 3,184
I wonder if SQL just doesn't like using that function with JOINs?
Jan 4 '19 #8

P: 20
It's possible. I'm extremely new to SQL. But based on my limited knowledge, I would assume it would complete the entire subquery and return it to the main query in the form of a table regardless of the method used to achieve the data.
Jan 4 '19 #9

twinnyfo
Expert Mod 2.5K+
P: 3,184
I'm sure NeoPa will have an intelligent answer on this one.

When SQL executes subqueries, I don't know if the query runs underneath to its full extent and then JOINs or if the top query executes, and the executes a subquery based upon the JOIN.

I know when I have chosen to use sub-queries (instead of things which are frowned upon, like using a Domain Aggregate Function) that I loose the flexibility of using that query as an updateable query. I've recently tried to eliminate all my DA functions from my queries (which is the "right thing to do") but had to go back because I was using them to update tables.

SQL can be finicky sometimes.
Jan 4 '19 #10

P: 20
The end goal of this query is to perform a one time Update/population of a Type field in my [Data - Inventory] table. I have been building it in steps to ease in troubleshooting. I have only been using SQL for a few weeks and am trying to avoid starting bad habits, so any advice is greatly appreciated!
Jan 4 '19 #11

twinnyfo
Expert Mod 2.5K+
P: 3,184
I can tell you right now that using this method will not allow you to use it as an UPDATE query.

Ther eis a part of me that wonders about your subquery design. Will something like this work?

Expand|Select|Wrap|Line Numbers
  1. SELECT [Data - Inventory].Component, 
  2.        [Data - Inventory].Description, 
  3.        Max(Concat(Nz([Data - Inventory].Component), Nz([Component Library].Type))) AS PartTypes
  4. FROM [Component Library] 
  5. LEFT JOIN [Data - Inventory] 
  6. ON [Data - Inventory].Description LIKE "*" &  [Component Library].Keyword & "*" 
  7. GROUP BY [Data - Inventory].Component;
Jan 4 '19 #12

P: 20
This works but yields the same result as the non-concatenated result I described previously. I like the idea of this suggestion avoiding the need of a subquery if I can get it to work.
Jan 4 '19 #13

twinnyfo
Expert Mod 2.5K+
P: 3,184
And, as I have been playing with this little function, I can't get the concatenation to work with any type of join. It works fine if there is only one table.

You might have to use VBA to cycle through all your required components and concatenate on the fly and update your table as you go.
Jan 4 '19 #14

twinnyfo
Expert Mod 2.5K+
P: 3,184
We may be a bit off center from this thread. I recommend you begin a new thread and we can work thorugh the specifics if you need.
Jan 4 '19 #15

P: 20
Done.
Jan 4 '19 #16

Post your reply

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