下面一段代码
sFields = " 凭证号码 电脑编号,产品标识,品牌,配件编号,配件名称,单价,数量,(case 接收单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end) 入库金额,(case 发出单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end ) 出库金额 "
mrsPT.Open "select " & sFields & " from viPartDetailAccount " & sWhere, ADO_CONN_60, adOpenKeyset, adLockOptimistic
Set rs = mrsPT.Clone
outMoney = 0
inMoney = 0
Num = 0
If rs.RecordCount > 0 Then
While Not rs.EOF
Num = Num + rs("数量")
outMoney = outMoney + rs("出库金额")
inMoney = inMoney + rs("入库金额")
rs.MoveNext
Wend
End If
mrsPT.AddNew
mrsPT(0) = "合 计"
mrsPT(1) = ""
mrsPT(2) = ""
mrsPT(3) = ""
mrsPT(4) = ""
mrsPT(5) = Null
mrsPT(6) = Num
mrsPT(7) = Format(inMoney, "#.0000") ''执行到这一步出错,提示多步操作产生错误
mrsPT(8) = Format(outMoney, "#.0000")怎么解决这个问题,请帮忙!
谢谢!
sFields = " 凭证号码 电脑编号,产品标识,品牌,配件编号,配件名称,单价,数量,(case 接收单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end) 入库金额,(case 发出单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end ) 出库金额 "
mrsPT.Open "select " & sFields & " from viPartDetailAccount " & sWhere, ADO_CONN_60, adOpenKeyset, adLockOptimistic
Set rs = mrsPT.Clone
outMoney = 0
inMoney = 0
Num = 0
If rs.RecordCount > 0 Then
While Not rs.EOF
Num = Num + rs("数量")
outMoney = outMoney + rs("出库金额")
inMoney = inMoney + rs("入库金额")
rs.MoveNext
Wend
End If
mrsPT.AddNew
mrsPT(0) = "合 计"
mrsPT(1) = ""
mrsPT(2) = ""
mrsPT(3) = ""
mrsPT(4) = ""
mrsPT(5) = Null
mrsPT(6) = Num
mrsPT(7) = Format(inMoney, "#.0000") ''执行到这一步出错,提示多步操作产生错误
mrsPT(8) = Format(outMoney, "#.0000")怎么解决这个问题,请帮忙!
谢谢!
While Not rs.EOF
Num = Num + rs("数量")
outMoney = Format(outMoney + rs("出库金额"),"##0.0000")
inMoney = Format(inMoney + rs("入库金额"),"##0.0000")
rs.MoveNext
Wend
End If
这样改下试试你是用的什么控件来显示的,LISTVIEW?
单步看看合计有没有出来!
If rs.RecordCount > 0 Then
While Not rs.EOF
Num = Num + rs("数量")
outMoney = Format((outMoney + rs("出库金额")),"##0.0000")
inMoney = Format((inMoney + rs("入库金额")),"##0.0000")
rs.MoveNext
Wend
End If如果是空的话就再TRIM下
mrsPT(7) = Val(Format(inMoney, "#.0000"))
mrsPT(8) = Val(Format(outMoney, "#.0000"))
这样你试一试
mrsPT(8) = Val(Format(inMoney, "#.0000"))
mrsPT(9) = Val(Format(outMoney, "#.0000"))
sFields = " 凭证号码 电脑编号,产品标识,品牌,配件编号,配件名称,单价,数量,(case 接收单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end) 入库金额,(case 发出单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end ) 出库金额 "
mrsPT.Open "select " & sFields & " from viPartDetailAccount " & sWhere & vbcrlf & "select '合计','','','','','',0,0,sum(入库金额),sum(出库金额) from (select ,(case 接收单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end) 入库金额,(case 发出单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end ) 出库金额 from viPartDetailAccount " & sWhere & ")", ADO_CONN_60, adOpenKeyset, adLockOptimistic
出来的就是明细加合计的记录集了,直接用就是了
mrsPT(7) = round(val(inMoney), 4)