以文本方式查看主题

-  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=87005)

--  作者:hrw68529
--  发布时间: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
--  发布时间:2016/6/30 17:14:00
--  
同时选择哪几个条件,是“或”条件还是“与”条件,msgbox(Filter)看看
--  作者:大红袍
--  发布时间: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
--  发布时间:2016/7/1 11:25:00
--  
大红袍:运行上述代码,当我选择“未鉴定”时,出现以下对话框,是怎么回事,麻烦你解决一下,谢谢
如下图:

--  作者:hrw68529
--  发布时间:2016/7/1 11:28:00
--  
如下图:
图片点击可在新窗口打开查看此主题相关图片如下:截图00.png
图片点击可在新窗口打开查看

--  作者:hrw68529
--  发布时间:2016/7/1 11:28:00
--  
就是说:未鉴定为空时,出现这种情况。
--  作者:大红袍
--  发布时间:2016/7/1 11:29:00
--  

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

 

改成

 

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


--  作者:hrw68529
--  发布时间:2016/7/1 11:40:00
--  
谢谢大红袍,按照你的代码,搞定,谢谢了。