以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  哎,还是关于多条件筛选的问题,自己写了代码,出错了。  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=60626)

--  作者:nclo
--  发布时间:2014/11/27 23:01:00
--  哎,还是关于多条件筛选的问题,自己写了代码,出错了。
表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

已经乱了,求大神帮忙。。



此主题相关图片如下:unnamed qq screenshot20141127224455.png
按此在新窗口浏览图片

此主题相关图片如下:unnamed qq screenshot20141127224418.png
按此在新窗口浏览图片

此主题相关图片如下:unnamed qq screenshot20141127224353.png
按此在新窗口浏览图片

--  作者:Bin
--  发布时间:2014/11/28 8:11:00
--  
出什么错?
--  作者:飞飞
--  发布时间:2014/11/28 8:24:00
--  
 这么复杂,看不了
--  作者:nclo
--  发布时间:2014/11/28 8:52:00
--  
就是代码不起作用。
--  作者:Bin
--  发布时间:2014/11/28 8:54:00
--  
没有进行筛选,说明没有符合条件的行.你弹出一下

messagebox.show(DataTables("表A").LoadFilter) 看看条件是什么 ,在对应检查自己的数据

--  作者:nclo
--  发布时间:2014/11/28 9:09:00
--  
上午上班没有带狗,BIN老师谢谢你,您站在专家的角度帮我看看我自己写的这个代码有问题没有????主要是这里有点麻烦,就是假设设置起止时间为2012年1月1日-2013年12月31日(时间是要筛选表B的)。那么datatable表A只加载除了AB以外的所有客户。
--  作者:有点甜
--  发布时间:2014/11/28 9:11:00
--  

 对应的例子发上来。

 

 你贴的代码,根本就不是你写的代码


--  作者:Bin
--  发布时间:2014/11/28 9:11:00
--  
目测没有问题,你弹出一下看看条件吧, 代码有问题就报错了.
--  作者:nclo
--  发布时间:2014/11/28 9:13:00
--  
BIN老师火眼金睛啊。。。。图片点击可在新窗口打开查看图片点击可在新窗口打开查看图片点击可在新窗口打开查看。。只能中午回去做个例子了,没有狗,狐表根本打不开。麻烦BIN老师中午给看看。。
--  作者:nclo
--  发布时间:2014/11/28 19:48:00
--  
Dim Filter As String

With e.Form.Controls("DateTimePicker1")

If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("DateTimePicker2")
    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

甜老师,bin老师,运行出错了。
图片点击可在新窗口打开查看此主题相关图片如下:qq photo20141128194702.jpg
图片点击可在新窗口打开查看