Hi All,
Been scratching my head and trawling through google for the last hour with no luck.
I have a SQL query written for VBA but due to the length it covers more than one line:
I get a complie error.
Just to go through what I have tried.
I've tried adding " " across each line with a & _ on the end... doesnt work.
I've tried doing each line with sSQL = blah blah
and a obj.execute(sSQL) ..doesnt work
I've tried doing each line with sSQL =
followed by the next line sSQL = sSQL & .....
Doesnt work...
Any help would be greatly appricated.
Been scratching my head and trawling through google for the last hour with no luck.
I have a SQL query written for VBA but due to the length it covers more than one line:
Code:
Sub refreshform()
Dim xteam As Integer
Dim sSQL As String
xteam = InputBox(Prompt:="Team Number Please.")
DoCmd.RunSQL ("SELECT tbl_store_" & xteam & ".Date, tbl_store_" & xteam & ".Partner, tbl_store_" & xteam & ".User, Sum(IIf([tbl_store_" & xteam & ".Retained]="Yes",1,0)) AS Saves, Sum(IIf([tbl_store_" & xteam & ".Retained]="Yes",0,1)) AS [No], Count([tbl_store_" & xteam & ".Retained]) AS [Total Logged], ([Saves]+[stdrens])/([rencalls]+[retcalls]) AS [Call_To_Save %], Sum(IIf([tbl_store_" & xteam & ".Type]="Standard Renewal",1,0)) AS StdRens, Sum(IIf([tbl_lean_" & xteam & ".Call Type]="Renewal Call",1,0)) AS RenCalls, Sum(IIf([tbl_lean_" & xteam & ".Call Type]="Retention Call",1,0)) AS RetCalls, [rencalls]/([rencalls]+[retcalls]) AS [RCP %]
FROM tbl_store_" & xteam & " INNER JOIN tbl_lean_" & xteam & " ON (tbl_store_" & xteam & ".User = tbl_lean_" & xteam & ".User) AND (tbl_store_" & xteam & ".Date = tbl_lean_" & xteam & ".Date) AND (tbl_store_" & xteam & ".Time = tbl_lean_" & xteam & ".Time) AND (tbl_store_" & xteam & ".[Policy Number] = tbl_lean_" & xteam & ".[Policy Number])
WHERE (((tbl_store_" & xteam & ".TLID) Like [Forms]![Frm_Main]![Cbo_TeamLeader]) AND ((tbl_store_" & xteam & ".Product) Like [Forms]![Frm_Main]![Cbo_Product]))
GROUP BY tbl_store_" & xteam & ".Date, tbl_store_" & xteam & ".Partner, tbl_store_" & xteam & ".User
HAVING (((tbl_store_" & xteam & ".Date)=[Forms]![Frm_Main]![Txt_Date]) AND ((tbl_store_" & xteam & ".Partner) Like [Forms]![Frm_Main]![Cbo_Partner]));")
End Sub
I get a complie error.
Just to go through what I have tried.
I've tried adding " " across each line with a & _ on the end... doesnt work.
I've tried doing each line with sSQL = blah blah
and a obj.execute(sSQL) ..doesnt work
I've tried doing each line with sSQL =
followed by the next line sSQL = sSQL & .....
Doesnt work...
Any help would be greatly appricated.