I have an Access front end with a SQL backend. I’m trying to add a couple of fields to a form. When I edit the working SQL statement for the Form_Open event and add the LEFT JOIN table I get the following error:<\/p>\n
There has been an error.
\n3075: Syntax error (missing operator) in query expression ‘CS.[SegmentID] = S.[SegmentID] LEFT JOIN DATR_ContractEnviroFee AS CEF ON C.[ContractID] = CEF.[ContractID’.
\nSource: DAO.Database
\nForm_InitialFeeHelper.Form_Open<\/p>\n
SQL Statement:<\/p>\n
Set rst = db.OpenRecordset( _
\n\"SELECT TotalNewSignFee AS NewInstall, OnContactCompanyId, ContractEntryID, \" & _
\n\"TotalMonthlyFee AS MonthlyFee, CEF.EnviroFee AS EnviroFeeAmt, CEF.Comment AS EnviroComment \" & _
\n\"NoEnviroFee As EnviroFee, Sponsor, TotalInitialFee AS InitialFee, \" & _
\n\"S.SegmentCode AS SegmentID, S.RouteName AS ROUTE, C.TotalInitialFeeBilled AS InitialFeeBilled, \" & _
\n\"S.DirectionCode AS DIRECTION, S.City AS CITY, S.StateCode, C.AssignedRep AS Rep, \" & _
\n\"C.[Free01] AS [Free01], C.[Free24] AS [Free24], C.[Free25] AS [Free25], C.[Disc01] AS [Disc01], \" & _
\n\"C.[DiscSF] AS [DiscSF], C.[DiscMF] AS [DiscMF], C.[FreeMonth01] AS [FreeMonth01], \" & _
\n“C.[FreeMonth24] AS [FreeMonth24], C.[GiftCard] AS [GiftCard],” & _
\n\"C.[FreeMonth25] AS [FreeMonth25], C.[Discount01] AS [Discount01], C.[DiscountSignFee] AS [DiscountSignFee], \" & _
\n“C.[DiscountMoFee] AS [DiscountMoFee], C.[GiftCardAmount] AS [GiftCardAmount],” & _
\n\"C.[FreeMonth01_Processed] AS [FreeMonth01_Processed], \" & _
\n\"C.[FreeMonth24_Processed] AS [FreeMonth24_Processed], C.[FreeMonth25_Processed] AS [FreeMonth25_Processed], \" & _
\n\"C.[Discount01_Processed] AS [Discount01_Processed], C.[DiscountSignFee_Processed] AS [DiscountSignFee_Processed], \" & _
\n\"C.[DiscountMoFee_Processed] AS [DiscountMoFee_Processed], C.[GiftCard_Processed] AS [GiftCard_Processed] \" & _
\n\"FROM (DATR_Contract AS C INNER JOIN DATR_ContractSegment AS CS ON C.ContractID = CS.ContractID) \" & _
\n\"INNER JOIN DAT_Segment AS S ON CS.[SegmentID] = S.[SegmentID] \" & _
\n\"LEFT JOIN DATR_ContractEnviroFee AS CEF ON C.[ContractID] = CEF.[ContractID] \" & _
\n\"WHERE C.ContractID = \" & conId, dbOpenDynaset, dbSeeChanges)<\/p>\n
Again, the statement was working fine until I tried to add the DATR_ContractEnviroFee table into the mix.<\/p>","upvoteCount":2,"answerCount":11,"datePublished":"2017-12-06T18:02:52.000Z","author":{"@type":"Person","name":"paigejacklin","url":"https://community.spiceworks.com/u/paigejacklin"},"suggestedAnswer":[{"@type":"Answer","text":"
I have an Access front end with a SQL backend. I’m trying to add a couple of fields to a form. When I edit the working SQL statement for the Form_Open event and add the LEFT JOIN table I get the following error:<\/p>\n
There has been an error.
\n3075: Syntax error (missing operator) in query expression ‘CS.[SegmentID] = S.[SegmentID] LEFT JOIN DATR_ContractEnviroFee AS CEF ON C.[ContractID] = CEF.[ContractID’.
\nSource: DAO.Database
\nForm_InitialFeeHelper.Form_Open<\/p>\n
SQL Statement:<\/p>\n
Set rst = db.OpenRecordset( _
\n\"SELECT TotalNewSignFee AS NewInstall, OnContactCompanyId, ContractEntryID, \" & _
\n\"TotalMonthlyFee AS MonthlyFee, CEF.EnviroFee AS EnviroFeeAmt, CEF.Comment AS EnviroComment \" & _
\n\"NoEnviroFee As EnviroFee, Sponsor, TotalInitialFee AS InitialFee, \" & _
\n\"S.SegmentCode AS SegmentID, S.RouteName AS ROUTE, C.TotalInitialFeeBilled AS InitialFeeBilled, \" & _
\n\"S.DirectionCode AS DIRECTION, S.City AS CITY, S.StateCode, C.AssignedRep AS Rep, \" & _
\n\"C.[Free01] AS [Free01], C.[Free24] AS [Free24], C.[Free25] AS [Free25], C.[Disc01] AS [Disc01], \" & _
\n\"C.[DiscSF] AS [DiscSF], C.[DiscMF] AS [DiscMF], C.[FreeMonth01] AS [FreeMonth01], \" & _
\n“C.[FreeMonth24] AS [FreeMonth24], C.[GiftCard] AS [GiftCard],” & _
\n\"C.[FreeMonth25] AS [FreeMonth25], C.[Discount01] AS [Discount01], C.[DiscountSignFee] AS [DiscountSignFee], \" & _
\n“C.[DiscountMoFee] AS [DiscountMoFee], C.[GiftCardAmount] AS [GiftCardAmount],” & _
\n\"C.[FreeMonth01_Processed] AS [FreeMonth01_Processed], \" & _
\n\"C.[FreeMonth24_Processed] AS [FreeMonth24_Processed], C.[FreeMonth25_Processed] AS [FreeMonth25_Processed], \" & _
\n\"C.[Discount01_Processed] AS [Discount01_Processed], C.[DiscountSignFee_Processed] AS [DiscountSignFee_Processed], \" & _
\n\"C.[DiscountMoFee_Processed] AS [DiscountMoFee_Processed], C.[GiftCard_Processed] AS [GiftCard_Processed] \" & _
\n\"FROM (DATR_Contract AS C INNER JOIN DATR_ContractSegment AS CS ON C.ContractID = CS.ContractID) \" & _
\n\"INNER JOIN DAT_Segment AS S ON CS.[SegmentID] = S.[SegmentID] \" & _
\n\"LEFT JOIN DATR_ContractEnviroFee AS CEF ON C.[ContractID] = CEF.[ContractID] \" & _
\n\"WHERE C.ContractID = \" & conId, dbOpenDynaset, dbSeeChanges)<\/p>\n
Again, the statement was working fine until I tried to add the DATR_ContractEnviroFee table into the mix.<\/p>","upvoteCount":2,"datePublished":"2017-12-06T18:02:52.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/1","author":{"@type":"Person","name":"paigejacklin","url":"https://community.spiceworks.com/u/paigejacklin"}},{"@type":"Answer","text":"
Those parenthesis look a little out of place in the beginning of your from clause. Are you sure those need to surround the first 2 tables?<\/p>\n
FROM (DATR_Contract AS C INNER JOIN DATR_ContractSegment AS CS ON C.ContractID = CS.ContractID)<\/p>","upvoteCount":0,"datePublished":"2017-12-06T18:10:40.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/2","author":{"@type":"Person","name":"craig","url":"https://community.spiceworks.com/u/craig"}},{"@type":"Answer","text":"
There also appears to be a comma missing after “CEF.Comment AS EnviroComment”.<\/p>","upvoteCount":0,"datePublished":"2017-12-06T18:14:22.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/3","author":{"@type":"Person","name":"craig","url":"https://community.spiceworks.com/u/craig"}},{"@type":"Answer","text":"
I removed the parentheses and still get a syntax error.<\/p>","upvoteCount":0,"datePublished":"2017-12-06T18:14:29.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/4","author":{"@type":"Person","name":"paigejacklin","url":"https://community.spiceworks.com/u/paigejacklin"}},{"@type":"Answer","text":"
Did you add the missing comma? Looks like that field was related to the new table you were trying to add.<\/p>","upvoteCount":0,"datePublished":"2017-12-06T18:19:53.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/5","author":{"@type":"Person","name":"craig","url":"https://community.spiceworks.com/u/craig"}},{"@type":"Answer","text":"
Yes. Same error still. I even took the fields out of the query and left the table just to make sure that the error happens upon adding the table into the query. Can I not do a LEFT JOIN in VBA?<\/p>","upvoteCount":0,"datePublished":"2017-12-06T18:21:56.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/6","author":{"@type":"Person","name":"paigejacklin","url":"https://community.spiceworks.com/u/paigejacklin"}},{"@type":"Answer","text":"
I’m not sure. Are you able to test just changing to INNER join, leaving the rest of the new part of the script as is?<\/p>","upvoteCount":0,"datePublished":"2017-12-06T18:25:14.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/7","author":{"@type":"Person","name":"craig","url":"https://community.spiceworks.com/u/craig"}},{"@type":"Answer","text":"
Instead of putting in a string value for your sql, I would assign that to a variable so you can print it out (debug) to see how it evaluates. That’s where we’ll be able to see the error.<\/p>","upvoteCount":0,"datePublished":"2017-12-06T18:44:57.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/8","author":{"@type":"Person","name":"michaelmcewen","url":"https://community.spiceworks.com/u/michaelmcewen"}},{"@type":"Answer","text":"
Your error shows a missing close bracket (]) even though your code snippet does not.<\/p>\n
It’s an awfully long statement, and I think I remember reading somewhere Openrecordset has a string length limit for the query string using DAO.<\/p>\n
It’s been a long time since I messed with DAO and VBA, so I could be mistaken.<\/p>","upvoteCount":0,"datePublished":"2017-12-06T19:58:14.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/9","author":{"@type":"Person","name":"larryshanahan","url":"https://community.spiceworks.com/u/larryshanahan"}},{"@type":"Answer","text":"
WHERE C.ContractID = \" & conId<\/p>\n
What is conId and where does it come from? Looks like an unqualified reference at first glance.<\/p>","upvoteCount":0,"datePublished":"2017-12-06T20:10:46.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/10","author":{"@type":"Person","name":"kevinhughes2","url":"https://community.spiceworks.com/u/kevinhughes2"}},{"@type":"Answer","text":"
The answer ended up being that I did not have the parentheses in the correct place for the table joins. I needed to do them the way they do in Access. In SQL you don’t need those parentheses.<\/p>","upvoteCount":0,"datePublished":"2017-12-13T14:07:20.000Z","url":"https://community.spiceworks.com/t/syntax-error-missing-operator-in-query-expression/622667/11","author":{"@type":"Person","name":"paigejacklin","url":"https://community.spiceworks.com/u/paigejacklin"}}]}}