下面一段代码 
 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")怎么解决这个问题,请帮忙!
谢谢!

解决方案 »

  1.   

    多步操作错误我了碰以过 ,是计算值就错误, 值可能为 NULL
      

  2.   

    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
    这样改下试试你是用的什么控件来显示的,LISTVIEW?
    单步看看合计有没有出来!
      

  3.   

    修改下
    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下
      

  4.   

    试试:
    mrsPT(7) = Val(Format(inMoney, "#.0000"))  
    mrsPT(8) = Val(Format(outMoney, "#.0000"))
      

  5.   

    用CASE生成的字段在记录集对象中应该是不能直接赋值的
      

  6.   

    而且发现你赋值的时候应该是数组对应错了的
    这样你试一试
            mrsPT(8) = Val(Format(inMoney, "#.0000"))
            mrsPT(9) = Val(Format(outMoney, "#.0000"))
      

  7.   

    或者用个比较直接的方法:
    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
    出来的就是明细加合计的记录集了,直接用就是了
      

  8.   

    如果是SQL SERVER,你将你的第一句改为:sFields = " isnull(凭证号码,'') as 凭证号码, isnull(电脑编号,'') as 电脑编号,isnull(产品标识,'') as 产品标识,isnull(品牌,'') as 品牌,isnull(配件编号,'') as 配件编号,isnull(配件名称,'') as 配件名称,isnull(单价,0) as 单价,isnull(数量,0) as 数量,(case 接收单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end) 入库金额,(case 发出单位编号 when '" & posID & "' then isnull(金额,0) else 0.0000 end ) 出库金额 "----------
    mrsPT(7) = round(val(inMoney), 4)