流水账的话估计要这样才行。
DataTables("明细账").DataRows.Clear()
if vars("起始日期") is nothing or vars("截止日期") is nothing or vars("工程编号") is nothing then
messagebox.show("起始日期或截止日期为空或工程编号为空")
else
for each dr as datarow in datatables("单据明细").datarows
for each dc as datacol in datatables("明细账").datacols
if dr("科目名称")=dc.name and dr("日期")>=vars("起始日期") and dr("日期")<=vars("截止日期") and dr("工程编号")=vars("工程编号") then
dim drr as row=tables("明细账").addnew()
drr(dc.name)=dr("金额")
drr("日期")=dr("日期")
drr("摘要")=dr("摘要")
drr("单据编号")=dr("单据编号")
drr("科目类别")=dr("科目类别")
end if
next
next
end if
Dim dt As DataTable = DataTables("明细账")
Dim sum,sum1,sum2 As Double
For Each dr As DataRow In dt.DataRows
sum = dt.Compute("Sum(工程款)","[单据编号] = '" & dr("单据编号") & "' And [日期] <= #" & dr("日期") & "#")
sum1 = dt.Compute("Sum(工资)","[单据编号] = '" & dr("单据编号") & "' And [日期] <= #" & dr("日期") & "#")
sum2 = dt.Compute("Sum(税金)","[单据编号] = '" & dr("单据编号") & "' And [日期] <= #" & dr("日期") & "#")
dr("可用款余额") = sum - sum1 - sum2
Next