Dim Filter As String = "1=1"
Dim filter2 As String = "1=1"
Dim filter3 As String = "1=1"
Dim filter4 As String = "1=1"
With e.Form.Controls("承运")
If .Value IsNot Nothing Then
Filter = " and 承运单位 = '" & .Value & "'"
Filter2 = " and 托运单位 = '" & .Value & "'"
Filter3 = " and 欠款人 = '" & .Value & "'"
Filter4 = " and 交款单位 = '" & .Value & "'"
End If
End With
With e.Form.Controls("起始时间")
If .Value IsNot Nothing Then
Filter = Filter & " and 日期 >= #" & .Value & "#"
filter2 &= " and " & "日期 >= #" & .Value & "#"
filter3 &= " and " & "日期 >= #" & .Value & "#"
filter4 &= " and " & "日期 >= #" & .Value & "#"
End If
End With
With e.Form.Controls("结束时间")
If .Value IsNot Nothing Then
Filter = Filter & " and 日期 <= #" & .Value & "#"
filter2 &= " and " & "日期 <= #" & .Value & "#"
filter3 &= " and " & "日期 <= #" & .Value & "#"
filter4 &= " and " & "日期 <= #" & .Value & "#"
End If
End With
If Filter > "" Then
Tables("应付").Filter = Filter
End If
Tables("应付.扣款").Filter = filter3
Tables("应付.应收").Filter = filter2
Tables("应付.已收款").Filter = filter4
Dim sum1, sum2, sum3, sum4 As Double
sum1 = Tables("应付").Compute("sum(金额)", filter)
sum2 = Tables("应收").Compute("sum(金额)", filter2)
sum3 = Tables("扣款").Compute("sum(金额)", filter3)
sum4 = Tables("已收款").Compute("sum(金额)", filter4)
e.Form.Controls("合计结果").Text = format(sum1 + sum3 - sum2 - sum4, "0.00")