|
zhufree,改成单引号报错信息就成,至少一个参数没有被指定值。
代码具体如下:
For m = 0 To UBound(dept)
sql = "SELECT SUM(4),SUM(5),SUM(6),SUM(7),SUM(8),SUM(9),SUM(10),SUM(11),SUM(12),SUM(1),SUM(2),SUM(3) FROM [Sheet1$] WHERE 成本中心 = "
sqlX = "SELECT 科目 FROM [X项目$] WHERE 固变区分 = '" '
sql = sql + sourcecostcenter + " AND 固变区分 = '" + dept(m) + "'"
sqlX = sqlX + dept(m) + "'"
Debug.Print sqlX
rsX.Open sqlX, cnn, adOpenKeyset, adLockBatchOptimistic
If rsX.RecordCount <> 0 Then
sql = sql + " AND 资产 <> '" & rsX.Fields.Item(0) & "'"
'sql = sql + " AND 资产 <> '" + CStr(rsX.Fields.Item(0)) + "'"
'sql = sql + "AND iif(isnull(科目),'',CStr(科目)) <> '" + CStr(rsX.Fields.Item(0)) + "'"
'Debug.Print sql
End If
rsX.Close
Set rsX = Nothing
rs.Open sql, cnn, adOpenKeyset, adLockBatchOptimistic
a4 = a4 + IIf(IsNull(rs.Fields.Item(0)), 0, rs.Fields.Item(0))
a5 = a5 + IIf(IsNull(rs.Fields.Item(1)), 0, rs.Fields.Item(1))
a6 = a6 + IIf(IsNull(rs.Fields.Item(2)), 0, rs.Fields.Item(2))
a7 = a7 + IIf(IsNull(rs.Fields.Item(3)), 0, rs.Fields.Item(3))
a8 = a8 + IIf(IsNull(rs.Fields.Item(4)), 0, rs.Fields.Item(4))
a9 = a9 + IIf(IsNull(rs.Fields.Item(5)), 0, rs.Fields.Item(5))
a10 = a10 + IIf(IsNull(rs.Fields.Item(6)), 0, rs.Fields.Item(6))
a11 = a11 + IIf(IsNull(rs.Fields.Item(7)), 0, rs.Fields.Item(7))
a12 = a12 + IIf(IsNull(rs.Fields.Item(8)), 0, rs.Fields.Item(8))
a1 = a1 + IIf(IsNull(rs.Fields.Item(9)), 0, rs.Fields.Item(9))
a2 = a2 + IIf(IsNull(rs.Fields.Item(10)), 0, rs.Fields.Item(10))
a3 = a3 + IIf(IsNull(rs.Fields.Item(11)), 0, rs.Fields.Item(11))
rs.Close
Set rs = Nothing
Next |
|