代码我测试没问题,如果选日期,修改红色代码即可
Dim dt As DataTable = DataTables("产成品收付存")
dt.DataRows.Clear
Dim dt1 As DataTable = DataTables("开piao明细")
Dim d1 As Date = new Date(Date.Today.year, Date.Today.Month,1)
Dim d2 As Date = d1.AddMonths(1)
For Each ary() As String In dt1.GetValues("型号|规格|单位")
Dim ndr As DataRow = dt.AddNew
ndr("型号") = ary(0)
ndr("规格") = ary(1)
ndr("单位") = ary(2)
Dim filter As String = "型号 = '" & ary(0) & "' and 规格 = '" & ary(1) & "' and 单位 = '" & ary(2) & "'"
filter = filter.Replace("*", "[*]")
output.show(filter & " and 开piao日期 < #" & d1 & "#")
Dim psum_sl As Double = dt1.Compute("sum(数量)", filter & " and 开piao日期 < #" & d1 & "#")
Dim sum_sl_in As Double = dt1.Compute("sum(数量)", filter & " and 开piao日期 >= #" & d1 & "# and 开piao日期 < #" & d2 & "# and 数量 >= 0")
Dim sum_sl_out As Double = dt1.Compute("sum(数量)", filter & " and 开piao日期 >= #" & d1 & "# and 开piao日期 < #" & d2 & "# and 数量 <= 0")
ndr("上月结存_数量") = psum_sl
ndr("本月收进_数量") = sum_sl_in
ndr("本月付出_数量") = sum_sl_out
Next