Foxtable(狐表)用户栏目专家坐堂 → 列表查询


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

主题:列表查询

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


加好友 发短信
等级:幼狐 帖子:155 积分:1556 威望:0 精华:0 注册:2011/4/8 14:38:00
列表查询  发帖心情 Post By:2013/3/29 13:05:00 [只看该作者]

以下是列表中【查询】按钮的代码:
Dim Filter As String
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "LCMC like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("DateTimePicker1")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "RQ >= #" & .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 & "RQ <= #" & .Value & "#"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        Filter = "KHBM like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "KHMC like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "LXR like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "LXDH like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "SHDZ like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "SSXQ like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "XSQD like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "KHDJ like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "BBBM like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "BBYWY like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "BBDGY like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "GZZT like '*" & .Value & "*'"
    End If
End With
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "BZ like '*" & .Value & "*'"
    End If
End With
If Filter > "" Then
    Tables("YXKH").Filter = Filter
End If
-------------------------------------------------------------------------
问题:我把其他字段的的条件注释掉,单独只留LCMC(如下),执行查询是正常的,但是像上面那样,全部执行的时候,LCMC这个字段的条件就失效,求解!
Dim Filter As String
With e.Form.Controls("模糊条件")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " OR "
        End If
        Filter = Filter & "LCMC like '*" & .Value & "*'"
    End If
End With
If Filter > "" Then
    Tables("YXKH").Filter = Filter
End If

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


加好友 发短信
等级:管理员 帖子:47448 积分:251048 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/3/29 14:27:00 [只看该作者]

你的条件中,有的用and连接起来,有的用Or连接起来。

 

A and B and c

 

只有b或c中有一个不成立,A不管是否成立,表达式都是false

 

A or B or c

 

只有b或c中有一个成立,A不管是否成立,表达式都是True

 

什么是有用and,什么时候用or,你自己首先要理清楚,还要注意用括号对条件分组。

 

 

 


 回到顶部