Private Sub SailShipmi()If CheAdd.Value = 0 Then
       sql_C = "select .lsxh,.k03,Carclass.cz,.k06,.total_tran_wei,gkfy.gkf01,.k13,.CarLength,.carWidth,.isaccount,(.datef+.timef) as selledtime,.sellerName " _
         & "From Mark  " _
         & " left join gkfy on .lsxh=gkfy.lsxh and .datef=gkfy.datef " _
         & " left join Carclass on Carclass.CarType=substring(.cldm,2,1) " _
         & " where k14='" & SshipNo & "' and regularno='" & Shbh & "' and convert(varchar(10),departdate,120)='" & Sdapartdate & "' and TPQK=0  and loadtype='10' " _
         & " order by .lsxh"
Else
    sql_C = "select .lsxh,.k03,Carclass.cz,.k06,.total_tran_wei,gkfy.gkf01,.k13,.CarLength,.carWidth,.isaccount,(.datef+.timef) as selledtime,.sellerName " _
      & "From Mark  " _
      & " left join gkfy on .lsxh=gkfy.lsxh and .datef=gkfy.datef " _
      & " left join Carclass on Carclass.CarType=substring(.cldm,2,1) " _
      & " where k14='" & SshipNo & "' and regularno='" & Shbh & "' and convert(varchar(10),departdate,120)='" & Sdapartdate & "' and TPQK=0 and  not loadtype='10'" _
      & " order by .lsxh"
'加长加宽Set rst_C = cn.OpenResultset(sql_C, rdOpenStatic, rdConcurReadOnly, rdExecDirect)
rst_row = rst_C.RowCount       '''''''''省略代码为在报表的显示
我现在想在程序中添加一个算法:
功能是判断CheAdd.Value = 0 时候 k061(k06的合计) 与 a 的比较,如果小于a,在消息框上显示k061-a的差为aa,并做出选择是否要增加,若选是,则对CheAdd.Value 不等于 0时候比较,CheAdd.Value 不等于0时候,会有若干个k06,自动从里面选择出
n个ko6,他们的和是小于aa的,并它们对应的loadtype改为等于10,之前他们对应的loadtype不等于10。请问下如何实现啊??End Sub

解决方案 »

  1.   

    没看懂你的意思...还有我认为你的代码要改进,差点没看出if语句中二个SQL语句的不同之处,我觉得你现在的写法很有问题,我大概改下,你看看如下是不是更好?
    Private Sub SailShipmi()     dim sql_loadtype as string
        
        If CheAdd.Value = 0 Then 
            sql_loadtype=" and loadtype='10' " 
        Else 
            sql_loadtype=" and not loadtype='10' "
        end if 
        
        sql_C = "select a.lsxh,a.k03,b.cz,a.k06,a.total_tran_wei,c.gkf01,a.k13,a.CarLength," _
            & "a.carWidth,a.isaccount,(a.datef+a.timef) as selledtime,a.sellerName " _ 
            & "From Mark a " _ 
            & "left join gkfy c on a.lsxh=c.lsxh and a.datef=c.datef " _ 
            & "left join Carclass b on b.CarType=substring(a.cldm,2,1) " _ 
            & "where k14='" & SshipNo & "' and regularno='" & Shbh & "' " _
            & "and convert(varchar(10),departdate,120)='" & Sdapartdate & "' " _
            & "and TPQK=0 " & sql_loadtype _ 
            & "order by a.lsxh" 
        '其它省略....End Sub