emorris1000
Registered User.
- Local time
- Today, 07:53
- Joined
- Feb 22, 2011
- Messages
- 125
I'm getting a syntax error on some SQL that is throwing me for a bit of a loop.
This code throws a compile syntax error:
Yet, this code works fine:
The only difference is that I changed the IIF in the SELECT to a specific field. Now, I've used this IIF statement before and it works fine. Any ideas what's going on? Also, just as a note, I can't put this code into the query design window due to the logical stuff in the bottom, so I'm having to debug this manually.
This code throws a compile syntax error:
Code:
Me.lbSearch.RowSource = "Select [General Data].PolyID, [General Data].SupCatID, [General Data].C6C2RatTarg, [General Data].H2C2RatTarg, [General Data].Productivity, IIf([TGPCGeneral]![PolyID] Is Not Null,"X","") AS GPC " _
& "From [General Data] " _
& "LEFT JOIN tGPCGeneral ON [General Data].PolyId = tGPCGeneral.PolyID " _
& "WHERE ([General Data].PolyID like ""*"" & Forms!fSearchPoly!tbPolyID & ""*"" OR Forms!fsearchPoly!tbPolyID is null) " _
& "AND ([General Data].SupCatID like ""*"" & Forms!fsearchPoly!tbSupCatID & ""*"" OR Forms!fsearchPoly!tbSupCatID is null) " _
& "AND ([General Data].ReactorID like Forms!fSearchPoly!cbReactorID OR Forms!fSearchPoly!cbReactorID is Null) " _
& "AND (([General Data].C6C2RatTarg > Forms!fSearchPoly!tbC6C2Min OR Forms!fSearchPoly!tbC6C2Min is Null) AND ([General Data].C6C2RatTarg < Forms!fSearchPoly!tbC6C2Max OR Forms!fSearchPoly!tbC6C2Max is Null)) " _
& "AND (([General Data].H2C2RatTarg > Forms!fSea
Yet, this code works fine:
Code:
Me.lbSearch.RowSource = "Select [General Data].PolyID, [General Data].SupCatID, [General Data].C6C2RatTarg, [General Data].H2C2RatTarg, [General Data].Productivity, tGPCGeneral.Mw " _
& "From [General Data] " _
& "LEFT JOIN tGPCGeneral ON [General Data].PolyId = tGPCGeneral.PolyID " _
& "WHERE ([General Data].PolyID like ""*"" & Forms!fSearchPoly!tbPolyID & ""*"" OR Forms!fsearchPoly!tbPolyID is null) " _
& "AND ([General Data].SupCatID like ""*"" & Forms!fsearchPoly!tbSupCatID & ""*"" OR Forms!fsearchPoly!tbSupCatID is null) " _
& "AND ([General Data].ReactorID like Forms!fSearchPoly!cbReactorID OR Forms!fSearchPoly!cbReactorID is Null) " _
& "AND (([General Data].C6C2RatTarg > Forms!fSearchPoly!tbC6C2Min OR Forms!fSearchPoly!tbC6C2Min is Null) AND ([General Data].C6C2RatTarg < Forms!fSearchPoly!tbC6C2Max OR Forms!fSearchPoly!tbC6C2Max is Null)) " _
& "AND (([General Data].H2C2RatTarg > Forms!fSearchPoly!tbH2C2Min OR Forms!fSearchPoly!tbH2C2Min is Null) AND ([General Data].H2C2RatTarg < Forms!fSearchPoly!tbH2C2Max OR Forms!fSearchPoly!tbH2C2Max is Null)) " _
& "ORDER BY [General Data].PolyID;"
The only difference is that I changed the IIF in the SELECT to a specific field. Now, I've used this IIF statement before and it works fine. Any ideas what's going on? Also, just as a note, I can't put this code into the query design window due to the logical stuff in the bottom, so I'm having to debug this manually.