Похоже, что вы включили некоторые параметры Recordset.Open
в строку SQL:
rs.Open "SELECT HEDNAME,DEPCODE,DEPNAME," & _
"ISNULL(A,0) as A, ISNULL(B,0) as B, ISNULL(C,0) as C, ISNULL(G,0) as G " & _
"from(SELECT HED.HEDCODE,HED.HEDNAME,payfil01.DEPCODE,payfil01.DEPNAME,payfil12.PARSSCB," & _
"payfil12.EMPSHFT FROM payfil01 INNER JOIN payfil12 ON payfil01.DEPCODE = payfil12.DEPCODE " & _
"INNER JOIN payfil04 ON payfil01.DEPCODE = payfil04.DEPCODE AND payfil12.EMPTYPE = payfil04.EMPTYPE" & _
" AND payfil12.EMPCODE = payfil04.EMPCODE INNER JOIN payfil05 ON payfil12.DEPCODE = payfil05.DEPCODE" & _
" AND payfil12.EMPTYPE = payfil05.EMPTYPE AND payfil12.EMPCODE = payfil05.EMPCODE Inner Join" & _
"(Select DEPCODE HEDCODE,DEPNAME HEDNAME from payfil01 Where RIGHT(DEPCODE,2) = '00')" & _
" HED On HED.HEDCODE = Left(payfil01.DEPCODE,2) + '-00' where ltrim(rtrim(payfil04.empcode))<>''" & _
" and payfil12.parsscb>0)Final PIVOT ( SUM(PARSSCB) FOR EMPSHFT IN ([A],[B],[C],[G]) )pvt order by HEDCODE asc " & _
", cn, adOpenStatic, adLockReadOnly" '<--- THIS PART SHOULD NOT BE IN THE STRING!!!
Обратите внимание, что последняя строка с аргументами для метода Open
случайно находится в строке.Это должно быть больше так:
rs.Open "SELECT HEDNAME,DEPCODE,DEPNAME," & _
"ISNULL(A,0) as A, ISNULL(B,0) as B, ISNULL(C,0) as C, ISNULL(G,0) as G " & _
"from(SELECT HED.HEDCODE,HED.HEDNAME,payfil01.DEPCODE,payfil01.DEPNAME,payfil12.PARSSCB," & _
"payfil12.EMPSHFT FROM payfil01 INNER JOIN payfil12 ON payfil01.DEPCODE = payfil12.DEPCODE " & _
"INNER JOIN payfil04 ON payfil01.DEPCODE = payfil04.DEPCODE AND payfil12.EMPTYPE = payfil04.EMPTYPE" & _
" AND payfil12.EMPCODE = payfil04.EMPCODE INNER JOIN payfil05 ON payfil12.DEPCODE = payfil05.DEPCODE" & _
" AND payfil12.EMPTYPE = payfil05.EMPTYPE AND payfil12.EMPCODE = payfil05.EMPCODE Inner Join" & _
"(Select DEPCODE HEDCODE,DEPNAME HEDNAME from payfil01 Where RIGHT(DEPCODE,2) = '00')" & _
" HED On HED.HEDCODE = Left(payfil01.DEPCODE,2) + '-00' where ltrim(rtrim(payfil04.empcode))<>''" & _
" and payfil12.parsscb>0)Final PIVOT ( SUM(PARSSCB) FOR EMPSHFT IN ([A],[B],[C],[G]) )pvt order by HEDCODE asc " & _
, cn, adOpenStatic, adLockReadOnly