以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  交叉检索搜索  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=172208)

--  作者:11112
--  发布时间:2021/9/29 13:44:00
--  交叉检索搜索
老师我想问一下有没有那一两个条件的交集或者是并集来查询搜索的
--  作者:有点蓝
--  发布时间:2021/9/29 13:47:00
--  
http://www.foxtable.com/webhelp/topics/0102.htm,理解一下or、and的区别
--  作者:11112
--  发布时间:2021/9/29 14:06:00
--  
交集跟并集是用and跟or是吧
--  作者:有点蓝
--  发布时间:2021/9/29 14:11:00
--  
是的
--  作者:11112
--  发布时间:2021/9/29 14:59:00
--  
我这个如果要交集的话是不是要Dim Filter As String
With e.Form.Controls("开始2")
    If .Value IsNot Nothing Then
        Filter = Filter & "记录时间 >= #" & .Value & "#"
    End If
End With

With e.Form.Controls("开始")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " or "
        End If
        Filter = Filter & "记录时间 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("结束")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " or "
        End If
        Filter = Filter & "记录时间 <= #" & .Value & "#"
    End If
End With
With e.Form.Controls("结束")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " or "
        End If
        Filter = Filter & "记录时间 <= #" & .Value & "#"
    End If
End With
If Filter > "" Then
    Tables("主控窗口_Table2").Filter = Filter
End If
图片点击可在新窗口打开查看此主题相关图片如下:1632898454(1).jpg
图片点击可在新窗口打开查看

--  作者:11112
--  发布时间:2021/9/29 15:04:00
--  
怎么两个结果合在一起
[此贴子已经被作者于2021/9/29 15:05:39编辑过]

--  作者:11112
--  发布时间:2021/9/29 15:08:00
--  
开始一跟结束一的结果跟开始二跟结束二的筛选合在一起怎么弄
--  作者:有点蓝
--  发布时间:2021/9/29 15:18:00
--  
Dim Filter As String
With e.Form.Controls("开始")
    If .Value IsNot Nothing Then
        Filter = "(记录时间 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("结束")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " and "
        End If
        Filter = Filter & "记录时间 <= #" & .Value & "#)"
    Else
        Filter = Filter & ")"
    End If
End With


With e.Form.Controls("开始2")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " or "
        End If
        Filter = Filter & "(记录时间 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("结束2")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " and "
        End If
        Filter = Filter & "记录时间 <= #" & .Value & "#)"
    Else
        Filter = Filter & ")"
    End If
End With
If Filter > "" Then
    Tables("主控窗口_Table2").Filter = Filter
End If

--  作者:11112
--  发布时间:2021/9/29 15:34:00
--  
Dim Filter As String
With e.Form.Controls("开始")
    If .Value IsNot Nothing Then
        Filter = "(记录时间 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("结束")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " and "
        End If
        Filter = Filter & "记录时间 <= #" & .Value & "#)"
    Else
        Filter = Filter & ")"
    End If
End With


With e.Form.Controls("开始2")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " or "
        End If
        Filter = Filter & "(记录时间 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("产品类别")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "产品类别 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("产品类别2")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " or "
        End If
        Filter = Filter & "产品类别 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("结束2")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " and "
        End If
        Filter = Filter & "记录时间 <= #" & .Value & "#)"
    Else
        Filter = Filter & ")"
    End If
End With



If Filter > "" Then
    Tables("主控窗口_Table2").Filter = Filter
End If 老师是不是一个是and 一个是or 他说我右括号太多了

--  作者:有点蓝
--  发布时间:2021/9/29 15:47:00
--  
建议分开2个条件,然后再合并

Dim Filter As String
With e.Form.Controls("开始")
    If .Value IsNot Nothing Then
        Filter = "记录时间 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("结束")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " and "
        End If
        Filter = Filter & "记录时间 <= #" & .Value & "#"
    End If
End With

Dim Filter2 As String
With e.Form.Controls("开始2")
    If .Value IsNot Nothing Then
        Filter2 = Filter2 & "记录时间 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("结束2")
    If .Value IsNot Nothing Then
        If Filter2 >"" Then
            Filter2 = Filter2 & " and "
        End If
        Filter2 = Filter2 & "记录时间 <= #" & .Value & "#"

    End If
End With
If Filter > "" AndAlso Filter2 > "" Then
    Tables("主控窗口_Table2").Filter = "(" & Filter & ") or (" & Filter2 & ")"
else
If Filter > "" Then
    Tables("主控窗口_Table2").Filter = Filter
elseIf Filter 2> "" Then
    Tables("主控窗口_Table2").Filter = Filter2
End If
End If

Filter有关的其它交集的条件放到Filter里,Filter2有关的其它交集的条件放到Filter2里