ConcatRelated Syntax Error (1 Viewer)

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
I'm using Allen Brown's ConcatRelated function. In my query I get a syntax error for a missing operator. I have tried every possible combination of quotation marks, brackets, single quotes etc imaginable and can not seem to get it to work. I got incorrect results with a couple of my attempts but just can't get what I need.
Any ideas would be appreciated!! (All are text fields)

My current query:
SELECT MDTRegionalCFN
ConcatRelated("Region","Copy of Skus","MDTRegionalCFN = '" & [MDTRegionalCFN] & "' )
FROM CopyOfSkus;
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:21
Joined
Sep 21, 2011
Messages
14,238
Try

Code:
SELECT MDTRegionalCFN
ConcatRelated("Region","[Copy of Skus]","MDTRegionalCFN = '" & [MDTRegionalCFN] & "'") 
FROM CopyOfSkus;

Missing " at the end.
 

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
Code:
SELECT MDTRegionalCFN
          ConcatRelated("Region","[Copy of Skus]","MDTRegionalCFN = '" & [MDTRegionalCFN] & "'" ) 
FROM CopyOfSkus;

Same Syntax Error: Missing Operator
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:21
Joined
Oct 29, 2018
Messages
21,455
Hi. I think you may be missing a comma.
Code:
 SELECT MDTRegionalCFN,
    ConcatRelated("Region","[Copy of Skus]","MDTRegionalCFN = '" & [MDTRegionalCFN] & "'" )  
FROM CopyOfSkus;
As an alternative, you could also try simple function.
 

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
I was missing a comma! Thank you.
Progress I think, now I get an error that says Data type mismatch in criteria expression.

Code:
SELECT DISTINCT CopyOfSkus.[MDTRegionalCFN], 
             ConcatRelated("[Region]","CopyofSkus","MDTRegionalCFN= " & [MDTRegionalCFN]) AS Regions
FROM CopyOfSkus;
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:21
Joined
Sep 21, 2011
Messages
14,238
You said they were all text?, so you need the single quotes for [MDTRegionalCFN] ?

I was missing a comma! Thank you.
Progress I think, now I get an error that says Data type mismatch in criteria expression.

Code:
SELECT DISTINCT CopyOfSkus.[MDTRegionalCFN], 
             ConcatRelated("[Region]","CopyofSkus","MDTRegionalCFN= " & [MDTRegionalCFN]) AS Regions
FROM CopyOfSkus;
 

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
I'm not sure what you mean.
Should I replace the " with '?
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:21
Joined
Sep 21, 2011
Messages
14,238
Look at my first post to you with regard to the variable [MDTRegionalCFN]
 

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
When I add the quotes back as we had them I get the syntax error missing operator again and it highlights the last set of quotation marks. The " ' " part.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:21
Joined
May 7, 2009
Messages
19,229
Code:
ConcatRelated("[Region]","CopyofSkus","MDTRegionalCFN= [COLOR="Red"]'[/COLOR]" & [MDTRegionalCFN] & "[COLOR="Red"]'[/COLOR]") AS Regions
 
Last edited:

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
This gives me syntax error missing operator and highlights the " ' " at the end.
Code:
SELECT DISTINCT CopyOfSkus.[MDTRegionalCFN], 

             ConcatRelated("[Region]","CopyofSkus","MDTRegionalCFN= ' " & [MDTRegionalCFN]" ' ") AS Regions

FROM CopyOfSkus;
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:21
Joined
Oct 29, 2018
Messages
21,455
This gives me syntax error missing operator and highlights the " ' " at the end.
Code:
SELECT DISTINCT CopyOfSkus.[MDTRegionalCFN], 

             ConcatRelated("[Region]","CopyofSkus","MDTRegionalCFN= ' " & [MDTRegionalCFN]" ' ") AS Regions

FROM CopyOfSkus;
Hi. What happens if you copy and paste the code I posted in post #4? I'm just curious if you'll get an error using it. You are missing an ampersand (&) this time, and you should remove the extra spaces around the single quote.
 

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
Spaces were just for the post to make it easier to see.
The following takes about 3 minutes to run and "Regions" is just blank for every record.

Code:
SELECT DISTINCT CopyOfSkus.[MDTRegionalCFN], 

             ConcatRelated("[Region]","CopyofSkus","MDTRegionalCFN= ' " & [MDTRegionalCFN]&" ' ") AS Regions

FROM CopyOfSkus;
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:21
Joined
Oct 29, 2018
Messages
21,455
Can you post a small copy of your db with test data?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:21
Joined
May 7, 2009
Messages
19,229
remove the extra spaces and add space to &:
Code:
ConcatRelated("[Region]","CopyofSkus","MDTRegionalCFN= [COLOR="Navy"]'[/COLOR]" & [MDTRegionalCFN] & "[COLOR="Navy"]'[/COLOR]") AS Regions
 

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
The database is attached.
 

Attachments

  • Database1.accdb
    1.8 MB · Views: 118

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:21
Joined
Oct 29, 2018
Messages
21,455
Hi. Thanks. You did have spaces in your code in your db. Check out Query2 in the attached updated copy of your db.
 

Attachments

  • Database1.accdb
    1.8 MB · Views: 121

Minty

AWF VIP
Local time
Today, 06:21
Joined
Jul 26, 2013
Messages
10,368
Okay here is the working query.

Code:
SELECT DISTINCT CopyOfSkus.MDTRegionalCFN, ConcatRelated("[Region]","CopyofSkus","MDTRegionalCFN= '" & [MDTRegionalCFN] & "'") AS Regions
FROM CopyOfSkus;

Adding indexes to the two fields being used mean its runs in about 6 seconds on my ancient underpowered laptop....


(I may have lied i7 vPro 32Gb ram M2 SSD)
 

kvar

Registered User.
Local time
Yesterday, 22:21
Joined
Nov 2, 2009
Messages
77
DBGuy, that works. Thank you for the solution!

However it seems odd that you would have to make a select distinct query and then pull the data from that. I can't see a reason why you can't just pull from the table directly. I guess it doesn't matter as long as it works, just irritates me I can't find a simpler solution.

Thank you!!
 

Minty

AWF VIP
Local time
Today, 06:21
Joined
Jul 26, 2013
Messages
10,368
Because you want to group by the first field?

If you don't you just get all your records back...?
 

Users who are viewing this thread

Top Bottom