以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  在范围内查询  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=185016)

--  作者:青丘狐
--  发布时间:2023/1/30 23:50:00
--  在范围内查询

 

Dim Filter As String
Dim KJMC() As String = {"摘要","经手人"}
For Each MC As String In KJMC
    Dim val As String = e.Form.Controls(MC).value
    If val > "" Then
        val = val.Replace("*", "[*]")
        If filter = "" Then
            filter = MC & " like \'*" & val & "*\'"
        Else
            filter = filter & " and " & MC & " like \'*" & val & "*\'"
        End If
    End If
Next

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("支出")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        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("结束日期")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
    End If
End With


If e.Form.Controls("方向借").Checked = True Then\' 如果收入选择了"借"
    If Filter > "" Then
        Filter = Filter & " And "
    End If
    Filter = Filter & "方向 = True"
End If
If e.Form.Controls("方向贷").Checked = True Then\' 如果支出选择了"贷"
    If Filter > "" Then
        Filter = Filter & " And "
    End If
    Filter = Filter & "方向 = False Or 方向 Is Null"
End If

If Filter > "" Then
    Tables("收支明细表").Filter = Filter
End If

 

请问要增加一个收入在范围内查询 比如从5到10的范围内查询,支出在范围内查询比如从5到10的范围内查询,请问要怎么改条件代码?


此主题相关图片如下:0130.png
按此在新窗口浏览图片

--  作者:有点蓝
--  发布时间:2023/1/31 8:36:00
--  
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("收入结束")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "收入 <= \'" & .Value & "\'"
    End If
End With

--  作者:青丘狐
--  发布时间:2023/1/31 19:52:00
--  

Dim Filter As String
Dim KJMC() As String = {"摘要","经手人"}
For Each MC As String In KJMC
    Dim val As String = e.Form.Controls(MC).value
    If val > "" Then
        val = val.Replace("*", "[*]")
        If filter = "" Then
            filter = MC & " like \'*" & val & "*\'"
        Else
            filter = filter & " and " & MC & " like \'*" & val & "*\'"
        End If
    End If
Next

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("支出")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        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("结束日期")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
    End If
End With


If e.Form.Controls("方向借").Checked = True Then\' 如果收入选择了"借"
    If Filter > "" Then
        Filter = Filter & " And "
    End If
    Filter = Filter & "方向 = True"
End If
If e.Form.Controls("方向贷").Checked = True Then\' 如果支出选择了"贷"
    If Filter > "" Then
        Filter = Filter & " And "
    End If
    Filter = Filter & "方向 = False Or 方向 Is Null"
End If


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("收入到")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        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("支出到")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "支出 <= \'" & .Value & "\'"
    End If
End With


If Filter > "" Then
    Tables("收支明细表").Filter = Filter
End If

 

谢谢老师解决了