以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]我这个查询条件,怎么没有效果?帮忙看看怎么回事,谢谢  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=46769)

--  作者:aduydgd
--  发布时间: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
--  发布时间:2014/2/27 14:27:00
--  
建议您用这个方法:
http://www.foxtable.com/help/topics/1485.htm

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

--  作者:aduydgd
--  发布时间:2014/2/27 14:33:00
--  
已经搞大半天了,也不提示错误,数据也不变化,所以贴出代码来求帮助了
--  作者:Bin
--  发布时间:2014/2/27 14:34:00
--  
参考2楼帮助,和提示.这样别人才能更好的帮助你.
--  作者:狐狸爸爸
--  发布时间:2014/2/27 14:44:00
--  
你单击命令代码编辑器窗口的重排按钮,在看看代码的结构,就知道自己的问题所在了。
你的:
Tables("信息追踪_table1").Filter = Filter
 
不是在最后执行,而是嵌入很多层的if之间,只有这些if的条件全部成立,才会执行筛选的。
[此贴子已经被作者于2014-2-27 14:47:54编辑过]

--  作者:狐狸爸爸
--  发布时间: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
--  发布时间:2014/2/27 14:52:00
--  
现在出提示了,每个条件都现实无法找到列
--  作者:狐狸爸爸
--  发布时间:2014/2/27 14:56:00
--  

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

 

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


--  作者:aduydgd
--  发布时间:2014/2/27 15:05:00
--  

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

 

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

 

 


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

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

--  作者:Bin
--  发布时间:2014/2/27 15:07:00
--  
是不是列名,标题没搞清楚?  还是类型没弄对?  把错误提示和拼接出来的条件 一并发出来看看吧