Foxtable(狐表)用户栏目专家坐堂 → [求助]我这个查询条件,怎么没有效果?帮忙看看怎么回事,谢谢


  共有3805人关注过本帖树形打印复制链接

主题:[求助]我这个查询条件,怎么没有效果?帮忙看看怎么回事,谢谢

帅哥哟,离线,有人找我吗?
狐狸爸爸
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251060 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2014/2/27 14:44:00 [显示全部帖子]

你单击命令代码编辑器窗口的重排按钮,在看看代码的结构,就知道自己的问题所在了。
你的:
Tables("信息追踪_table1").Filter = Filter
 
不是在最后执行,而是嵌入很多层的if之间,只有这些if的条件全部成立,才会执行筛选的。
[此贴子已经被作者于2014-2-27 14:47:54编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251060 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2014/2/27 14:46:00 [显示全部帖子]

具体的逻辑只有你清楚,最重要的是将执行筛选这部分提出来,放在最后,其他自己调整:

 

Dim Filter As String
With e.Form.Controls("jieshou")
    If .Value IsNot Nothing Then
        Filter = "jieshoudanwei = '" & .Value & "'"
    End If
End With
With e.Form.Controls("laiyuan")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "laiyuanjing = '" & .Value & "'"
    End If
End With
With e.Form.Controls("danju")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "danjuzhuangtai = '" & .Value & "'"
    End If
End With
With e.Form.Controls("weixiu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "weixiuzhuangtai = '" & .Value & "'"
    End If
End With
With e.Form.Controls("chanpin")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "chanpin_xinghao = '" & .Value & "'"
    End If
End With
With e.Form.Controls("jihao")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "jihao = '" & .Value & "'"
    End If
End With
If e.Form.Controls("sxriqi").Checked = True
    With e.Form.Controls("kai")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "sx_riqi >= #" & .Value & "#"
        End If
    End With
End If
With e.Form.Controls("jieshu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "sx_riqi <= #" & .Value & "#"
    End If
End With
If e.Form.Controls("jieriqi").Checked = True
    With e.Form.Controls("kai")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "jieshouriqi >= #" & .Value & "#"
        End If
    End With
End If
With e.Form.Controls("jieshu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "jieshouriqi <= #" & .Value & "#"
    End If
End With
If e.Form.Controls("pairiqi").Checked = True
    With e.Form.Controls("kai")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "pai_riqi >= #" & .Value & "#"
        End If
    End With
End If
With e.Form.Controls("jieshu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "pai_riqi <= #" & .Value & "#"
    End If
End With
If e.Form.Controls("huiriqi").Checked = True
    With e.Form.Controls("kai")
        If .Value IsNot Nothing Then
            If Filter >"" Then
                Filter = Filter & " And "
            End If
            Filter = Filter & "weixiuriqi >= #" & .Value & "#"
        End If
    End With
End If
With e.Form.Controls("jieshu")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "weixiuriqi <= #" & .Value & "#"
    End If
End With
If Filter > "" Then
    Tables("信息追踪_table1").Filter = Filter
End If

[此贴子已经被作者于2014-2-27 14:48:58编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251060 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2014/2/27 14:56:00 [显示全部帖子]

用Messagebox显示一下合成的条件:

 

''''前面的代码
MessageBox.show(Filter)
If Filter > "" Then
    Tables("信息追踪_table1").Filter = Filter
End If
 
看看合成的表达式是什么,没有找到,就说明没有符合条件的数据。


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251060 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2014/2/27 15:12:00 [显示全部帖子]

计算机是最机械的,是不会撒谎的,说找不到这列,那肯定就不存在"danjuzhuangtai"这一列。

看看自己是不是把列名和列标题搞混了,搞不定就做个简单例子发上来。

 

 

[此贴子已经被作者于2014-2-27 15:13:11编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251060 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2014/2/27 15:15:00 [显示全部帖子]

例如:

 

baoxiuxingzhi As [保修性质]

 

现在的列名是“保修性质",不是"baoxiuxingzhi"

 

你这是筛选,处理的是已经加载进来的数据,全部按照新的列名调整你的代码。

[此贴子已经被作者于2014-2-27 15:15:37编辑过]

 回到顶部