Foxtable(狐表)用户栏目专家坐堂 → [求助]查询代码如何组合查询?


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

主题:[求助]查询代码如何组合查询?

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


加好友 发短信
等级:五尾狐 帖子:1111 积分:8577 威望:0 精华:0 注册:2012/7/10 9:09:00
[求助]查询代码如何组合查询?  发帖心情 Post By:2016/6/30 16:19:00 [只看该作者]

查询代码如何组合查询?当选一个选项时,可以查询,但同时选择多个条件时,无法查询,如何解决?
代码如下:Dim Filter As String
With e.Form.Controls("comboBox1")
    If .Value IsNot Nothing Then
        Filter = "批次 = '" & .Value & "'"
    End If
End With

With e.Form.Controls("comboBox15")
    If .Value IsNot Nothing Then
        Filter = "年度 = '" & .Value & "'"
    End If
End With
With e.Form.Controls("comboBox16")
    If .Value IsNot Nothing Then
        Filter = "姓名 = '" & .Value & "'"
    End If
End With
With e.Form.Controls("comboBox01")
    If .Value IsNot Nothing Then
        Filter = "鉴定类别 = '" & .Value & "'"
    End If
End With


If e.Form.Controls("yjd").Checked = True ' 如果付款状态选择了"已付"
    If Filter >"" Then
        Filter = Filter & " And "
    End If
    Filter = Filter & "是否鉴定 = true"
End If
If e.Form.Controls("wjd").Checked = True ' 如果付款状态选择了"未付"
    If Filter >"" Then
        Filter = Filter & " And "
    End If
    Filter = Filter & "是否鉴定 = false"
End If

'If Filter > "" Then
    'Tables("劳动能力鉴定_鉴定").Filter = Filter
'End If
'
If Filter > "" Then
    Dim str As String = Tables("劳动能力鉴定_鉴定").DataTable.GetComboListString("_Identify", filter)
    Tables("劳动能力鉴定_鉴定").Filter = "_Identify in (" & str.replace("|", ",") & ")"
End If
'Tables("劳动能力鉴定_鉴定").Sort = "编号"

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


加好友 发短信
等级:狐神 帖子:5015 积分:25363 威望:0 精华:0 注册:2015/8/18 9:21:00
  发帖心情 Post By:2016/6/30 17:14:00 [只看该作者]

同时选择哪几个条件,是“或”条件还是“与”条件,msgbox(Filter)看看

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/6/30 17:55:00 [只看该作者]

Dim Filter As String = "1=1"
With e.Form.Controls("comboBox1")
    If .Value IsNot Nothing Then
        Filter &= " and 批次 = '" & .Value & "'"
    End If
End With


With e.Form.Controls("comboBox15")
    If .Value IsNot Nothing Then
        Filter &= " and 年度 = '" & .Value & "'"
    End If
End With
With e.Form.Controls("comboBox16")
    If .Value IsNot Nothing Then
        Filter &= " and 姓名 = '" & .Value & "'"
    End If
End With
With e.Form.Controls("comboBox01")
    If .Value IsNot Nothing Then
        Filter &= " and 鉴定类别 = '" & .Value & "'"
    End If
End With

 


If e.Form.Controls("yjd").Checked = True ' 如果付款状态选择了"已付"

    Filter = Filter & " and 是否鉴定 = true"
End If
If e.Form.Controls("wjd").Checked = True ' 如果付款状态选择了"未付"
    Filter = Filter & " and 是否鉴定 = false"
End If

msgbox(filter)

If Filter > "" Then
    Dim str As String = Tables("劳动能力鉴定_鉴定").DataTable.GetComboListString("_Identify", filter)
    Tables("劳动能力鉴定_鉴定").Filter = "_Identify in (" & str.replace("|", ",") & ")"
End If
'Tables("劳动能力鉴定_鉴定").Sort = "编号"


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


加好友 发短信
等级:五尾狐 帖子:1111 积分:8577 威望:0 精华:0 注册:2012/7/10 9:09:00
  发帖心情 Post By:2016/7/1 11:25:00 [只看该作者]

大红袍:运行上述代码,当我选择“未鉴定”时,出现以下对话框,是怎么回事,麻烦你解决一下,谢谢
如下图:

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


加好友 发短信
等级:五尾狐 帖子:1111 积分:8577 威望:0 精华:0 注册:2012/7/10 9:09:00
  发帖心情 Post By:2016/7/1 11:28:00 [只看该作者]

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

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


加好友 发短信
等级:五尾狐 帖子:1111 积分:8577 威望:0 精华:0 注册:2012/7/10 9:09:00
  发帖心情 Post By:2016/7/1 11:28:00 [只看该作者]

就是说:未鉴定为空时,出现这种情况。

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/1 11:29:00 [只看该作者]

Tables("劳动能力鉴定_鉴定").Filter = "_Identify in (" & str.replace("|", ",") & ")"

 

改成

 

Tables("劳动能力鉴定_鉴定").Filter = "_Identify in (-1," & str.replace("|", ",") & ")"


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


加好友 发短信
等级:五尾狐 帖子:1111 积分:8577 威望:0 精华:0 注册:2012/7/10 9:09:00
  发帖心情 Post By:2016/7/1 11:40:00 [只看该作者]

谢谢大红袍,按照你的代码,搞定,谢谢了。

 回到顶部