Trouble with code that is broken over multiple lines (space_)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I've got the following code (generated by recording a macro), but it doesn't
work. I've not modified it. I'm sure it's because of the way it's spanning
lines.

Apologies - I'm not sure whether it's possible to duplicate the formatting
here, so I'll paste all the code and then the excerpt that excel highlights
red (syntax error)

Any ideas gratefully received.

Tom.

WHOLE CODE:

Sub Macro1()

Sheets("Initial Query").Select
Range("D3").Select
With Selection.QueryTable
.Connection = _
"ODBC;DRIVER=SQL Server;SERVER=CSCSQL02;UID=kcarswell;APP=Microsoft
Office XP;WSID=HP1847;DATABASE=dwAWD;Trusted_Connection=Yes"
.CommandText = Array( _
"SELECT DISTINCT dim_Adviser.AdviserAlias,
Sum(fct_CommissionAccrued.AccruedAmount) AS 'Sum of
AccruedAmount'"&chr(13)&""&chr(10)&"FROM dwAWD.dbo.dim_Adviser dim_Adviser,
dwAWD.dbo.dim_CommissionType dim_CommissionType, d" _
, _
"wAWD.dbo.dim_PolicyKPI dim_PolicyKPI,
dwAWD.dbo.fct_CommissionAccrued fct_CommissionAccrued,
dwAWD.dbo.vdw_OnRiskCalendar vdw_OnRiskCalendar"&chr(13)&""&chr(10)&"WHERE
fct_CommissionAccrued.AdviserID = dim_Adviser.Advise" _
, _
"rID AND fct_CommissionAccrued.CommissionTypeID =
dim_CommissionType.CommissionTypeID AND fct_CommissionAccrued.PolicyKPIID =
dim_PolicyKPI.PolicyKPIId AND vdw_OnRiskCalendar.OnRiskDateID = fct_Commiss" _
, _
"ionAccrued.PolicyOnRiskDateID AND
((dim_CommissionType.CommissionReallocatedAccType='Adviser') AND
(dim_CommissionType.CommissionSubPhase In ('Fee','Initial')) AND
(dim_PolicyKPI.KPI_OnRisk='OnRisk') " _
, _
"AND (vdw_OnRiskCalendar.TimeDate Between {ts '2007-01-01 00:00:00'}
And {ts '2007-12-31 00:00:00'}))"&chr(13)&""&chr(10)&"GROUP BY
dim_Adviser.AdviserAlias, dim_Adviser.AdviserUnused,
dim_Adviser.Department"&chr(13)&""&chr(10)&"HAVING (dim_" _
,)
.Refresh BackgroundQuery:=False
End With
End Sub


BROKEN SECTION:

..CommandText = Array( _
"SELECT DISTINCT dim_Adviser.AdviserAlias,
Sum(fct_CommissionAccrued.AccruedAmount) AS 'Sum of
AccruedAmount'"&chr(13)&""&chr(10)&"FROM dwAWD.dbo.dim_Adviser dim_Adviser,
dwAWD.dbo.dim_CommissionType dim_CommissionType, d" _
, _
"wAWD.dbo.dim_PolicyKPI dim_PolicyKPI,
dwAWD.dbo.fct_CommissionAccrued fct_CommissionAccrued,
dwAWD.dbo.vdw_OnRiskCalendar vdw_OnRiskCalendar"&chr(13)&""&chr(10)&"WHERE
fct_CommissionAccrued.AdviserID = dim_Adviser.Advise" _
, _
"rID AND fct_CommissionAccrued.CommissionTypeID =
dim_CommissionType.CommissionTypeID AND fct_CommissionAccrued.PolicyKPIID =
dim_PolicyKPI.PolicyKPIId AND vdw_OnRiskCalendar.OnRiskDateID = fct_Commiss" _
, _
"ionAccrued.PolicyOnRiskDateID AND
((dim_CommissionType.CommissionReallocatedAccType='Adviser') AND
(dim_CommissionType.CommissionSubPhase In ('Fee','Initial')) AND
(dim_PolicyKPI.KPI_OnRisk='OnRisk') " _
, _
"AND (vdw_OnRiskCalendar.TimeDate Between {ts '2007-01-01 00:00:00'}
And {ts '2007-12-31 00:00:00'}))"&chr(13)&""&chr(10)&"GROUP BY
dim_Adviser.AdviserAlias, dim_Adviser.AdviserUnused,
dim_Adviser.Department"&chr(13)&""&chr(10)&"HAVING (dim_" _
,)
.



Relevant Pages

  • Re: Subset Sum problem (w/ limited scope)
    ... The "Subset Sum" problem (stated various ways depending on what you ... a subset of those integers that sums up to zero. ... Are there going to be duplicate values in your original array? ...
    (comp.lang.fortran)
  • Re: How can I find the greatest possible sum within 12 months? A newbie...
    ... It may be because you have headers, and when I tied it first I omitted ... You may have omitted to enter it as an array formula (see notes on ... the starting sum is in A2 and the end sum is in A123. ... Excel will insert them for you. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Explanation of SUMPRODUCT
    ... I don't even think you need to enter it as an array ... Yes, we know this, but in this case SUM is an array formula SUMPRODUCT ... > each element is the number of times the corresponding cell value appears ...
    (microsoft.public.excel.programming)
  • Re: Simple but confusing algorith question
    ... As you mention that this is an interview question ... ... through the array, then query against the structure somehow. ... structure and the cost of querying the data structure. ... array 1,2,3,4 sum = 5 ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple but confusing algorith question
    ... through the array, then query against the structure somehow. ... structure and the cost of querying the data structure. ... array 1,2,3,4 sum = 5 ... indices that equal the input sum parameter. ...
    (microsoft.public.dotnet.languages.csharp)