Hi everyone,
in a previous thread I posted a question about changing a table reference within a CreateQueryDef code. I managed to do so by defining various string variables and than include an Iif-Clause within the CreateQueryDef which defines which str variable to pull.
Now I get an error message, which I can't seem to solve. any help would be much appreciated. I only pasted the relevant part of the code.
The CreateQueryDef is like this:
===================
Set qryNew = db.CreateQueryDef("QueryMaster", "SELECT [MasterTable].* , Iif ([MasterTable].[NewTyp] Alike " & "'NAM'" & ", " & strnam & ", Iif([MasterTable].[NewTyp] Alike " & "'OLD'" & ", " & strold & ", " & strnew & ")) ")
===================
For example strnam ( strold and strnew are defined similar with just a different table reference) is defined as this:
===================
strnam = "([" & [Forms]![MainSwitchboard]!cmdmonth.Value & "LeaseAct]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "NoneLeaseAct]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "BacklogLeaseNoHold]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "BacklogNoneLeaseNoHold]) as " & [Forms]![MainSwitchboard]!cmdmonth.Value & "Achievment, " _
& " Iif([" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Bud] <>0,[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Achievment]/[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Bud],0) as " & [Forms]![MainSwitchboard]!cmdmonth.Value & "Reach, " _
& " [" & [Forms]![MainSwitchboard]!cmdmonth.Value & "LeaseAct] +[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "NoneLeaseAct]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "BacklogLeaseNoHold]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "BacklogNoneLeaseNoHold] as " & [Forms]![MainSwitchboard]!cmdmonth.Value & "MarketingBase, " _
& " Iif([" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Reach]<0.6,0," _
& " IIf([" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Reach]>=0.6 And [" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Reach]<0.7,[tblNAMRates].[From60to6999Rate], 0)) as " & [Forms]![MainSwitchboard]!cmdmonth.Value & "Rate into tblmaster " _
& " FROM [MasterTable], [tblNAMRates], [tblNewHireRates], [tblMarketingRates], [tblLeasingRates]; "
=====================
I think the problem is in the CreateQuery within the Iif-Clause and in the above example with the - Alike " & "'NAM'" & " - structure. Error says "syntax error, missing operator....".
Many thanks for any help on this.
in a previous thread I posted a question about changing a table reference within a CreateQueryDef code. I managed to do so by defining various string variables and than include an Iif-Clause within the CreateQueryDef which defines which str variable to pull.
Now I get an error message, which I can't seem to solve. any help would be much appreciated. I only pasted the relevant part of the code.
The CreateQueryDef is like this:
===================
Set qryNew = db.CreateQueryDef("QueryMaster", "SELECT [MasterTable].* , Iif ([MasterTable].[NewTyp] Alike " & "'NAM'" & ", " & strnam & ", Iif([MasterTable].[NewTyp] Alike " & "'OLD'" & ", " & strold & ", " & strnew & ")) ")
===================
For example strnam ( strold and strnew are defined similar with just a different table reference) is defined as this:
===================
strnam = "([" & [Forms]![MainSwitchboard]!cmdmonth.Value & "LeaseAct]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "NoneLeaseAct]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "BacklogLeaseNoHold]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "BacklogNoneLeaseNoHold]) as " & [Forms]![MainSwitchboard]!cmdmonth.Value & "Achievment, " _
& " Iif([" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Bud] <>0,[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Achievment]/[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Bud],0) as " & [Forms]![MainSwitchboard]!cmdmonth.Value & "Reach, " _
& " [" & [Forms]![MainSwitchboard]!cmdmonth.Value & "LeaseAct] +[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "NoneLeaseAct]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "BacklogLeaseNoHold]+[" & [Forms]![MainSwitchboard]!cmdmonth.Value & "BacklogNoneLeaseNoHold] as " & [Forms]![MainSwitchboard]!cmdmonth.Value & "MarketingBase, " _
& " Iif([" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Reach]<0.6,0," _
& " IIf([" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Reach]>=0.6 And [" & [Forms]![MainSwitchboard]!cmdmonth.Value & "Reach]<0.7,[tblNAMRates].[From60to6999Rate], 0)) as " & [Forms]![MainSwitchboard]!cmdmonth.Value & "Rate into tblmaster " _
& " FROM [MasterTable], [tblNAMRates], [tblNewHireRates], [tblMarketingRates], [tblLeasingRates]; "
=====================
I think the problem is in the CreateQuery within the Iif-Clause and in the above example with the - Alike " & "'NAM'" & " - structure. Error says "syntax error, missing operator....".
Many thanks for any help on this.