以下这段代码先通过采购订单主表与采购订单表联合生成一个订单查询表,然后再查根据条件筛选所需数据,如果数据非常多时这样查询的工作量就会非常大,我的想法是通过先在主表查询符合部分条件(因为有部分条件并不在主表中而采购订单表中)的数据,然后再联合生成一个订单查询表,再筛选,但是不知道怎么改。
Dim sg As New SQLJoinTableBuilder("订单查询","采购订单主表")
sg.AddTable("采购订单主表","订单编号","采购订单","订单编号")
sg.AddCols("{采购订单主表}.订单编号","{采购订单主表}.供应商","{采购订单主表}.日期","审核","审批","{采购订单主表}.部门","品牌","型号","数量","含税单价","{采购订单主表}.金额")
sg.Build()
MainTable = Tables("订单查询")
Dim Filter As String
With e.Form.Controls("部门")
If .Value IsNot Nothing Then
Filter = "部门 = '" & .Value & "'"
End If
End With
With e.Form.Controls("供应商")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "供应商 = '" & .Value & "'"
End If
End With
With e.Form.Controls("品牌")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "品牌 = '" & .Value & "'"
End If
End With
With e.Form.Controls("开始日期")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 >= #" & .Value & "#"
End If
End With
With e.Form.Controls("截止日期")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 <= #" & .Value & "#"
End If
End With
If e.Form.Controls("已审核").Checked = True ' 如果付款状态选择了"已付"
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "审核 IsNot Null"
End If
If e.Form.Controls("未审核").Checked = True ' 如果付款状态选择了"未付"
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "审核 = False Or 审核 Is Null"
End If
If Filter > "" Then
Tables("订单查询").Filter = Filter
End If