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


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

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

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


加好友 发短信
等级:三尾狐 帖子:681 积分:5332 威望:0 精华:0 注册:2011/12/26 20:43:00
[求助]我这个查询条件,怎么没有效果?帮忙看看怎么回事,谢谢  发帖心情 Post By:2014/2/27 14:18:00 [只看该作者]

用代码生成的表,SQLQuery类型,弄出来查询无效果,还是哪些地方写的有问题,高手帮忙改改,谢谢

 

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
    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
        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
            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
                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
            End If
        End If
    End If
End If


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


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/2/27 14:27:00 [只看该作者]

建议您用这个方法:
http://www.foxtable.com/help/topics/1485.htm

先找出是哪一行出错,然后分析原因,搞不定,贴出代码,并告诉我们运行到哪一行出错,以及错误提示。

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


加好友 发短信
等级:三尾狐 帖子:681 积分:5332 威望:0 精华:0 注册:2011/12/26 20:43:00
  发帖心情 Post By:2014/2/27 14:33:00 [只看该作者]

已经搞大半天了,也不提示错误,数据也不变化,所以贴出代码来求帮助了

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


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/2/27 14:34:00 [只看该作者]

参考2楼帮助,和提示.这样别人才能更好的帮助你.

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


加好友 发短信
等级:管理员 帖子:47448 积分:251054 威望: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编辑过]

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


加好友 发短信
等级:管理员 帖子:47448 积分:251054 威望: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编辑过]

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


加好友 发短信
等级:三尾狐 帖子:681 积分:5332 威望:0 精华:0 注册:2011/12/26 20:43:00
  发帖心情 Post By:2014/2/27 14:52:00 [只看该作者]

现在出提示了,每个条件都现实无法找到列

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


加好友 发短信
等级:管理员 帖子:47448 积分:251054 威望: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
 
看看合成的表达式是什么,没有找到,就说明没有符合条件的数据。


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


加好友 发短信
等级:三尾狐 帖子:681 积分:5332 威望:0 精华:0 注册:2011/12/26 20:43:00
  发帖心情 Post By:2014/2/27 15:05:00 [只看该作者]

MessageBox.show(Filter)会现实指出的条件,点确定后就会直接跳出来一个未找到列***,但是我很确定我的列是存在的,这个表我使用的是SQLQuery类型的,

 

每个指定的条件都会跳出相对应的列不存在

 

 


图片点击可在新窗口打开查看此主题相关图片如下:1.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:2.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2014-2-27 15:06:31编辑过]

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


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/2/27 15:07:00 [只看该作者]

是不是列名,标题没搞清楚?  还是类型没弄对?  把错误提示和拼接出来的条件 一并发出来看看吧

 回到顶部
总数 18 1 2 下一页