表A是专合社基础资料表,假设里面有100个专合社,每个客户有唯一的编号(工商登记号)。表A,表B以编号关联。表B是政府支持专合社统计表,假设里面有A,B,C三个专合社分别于2012年1月1日,2013年1月1日,2014年1月1日有一笔购买记录。
现在做了一个窗口,做了起止时间timepicker,做了筛选按钮,想实现的功能为:假设设置起止时间为2012年1月1日-2013年12月31日(时间是要筛选表B的)。那么datatable表A只加载除了AB以外的所有客户,然后如果条件设置里combobox1设置为全市,就加载所有县区的符合条件的的,设置为某县就只加载某县符合条件的。combobox2设置为专合社类别,设置全部类别就加载所有符合条件的。设置某类型(如畜牧养殖类)就只加载畜牧养殖类型中符合条件的。自己写的开始筛选代码如下。(甜老师早上已经指点)
Dim Filter As String
With e.Form.Controls("StartDate") |
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 >= #" & .Value & "#"
End If
End With
With e.Form.Controls("EndDate")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 <= #" & .Value & "#"
End If
End With
With e.Form.Controls("combobox1")
If .Value IsNot Nothing Then
Filter = "区域 = '" & .Value & "'"
End If
End With
With e.Form.Controls("combobox2")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "专合社类别 = '" & .Value & "'"
End If
End With
DataTables("表A").LoadFilter = "编号 not in (select 编号 from {表B} where " & filter & ")"
DataTables("表A").Load
已经乱了,求大神帮忙。。