以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=76216)

--  作者:SMXTB
--  发布时间:2015/10/23 22:49:00
--  [求助]

是如果有多个文本控件,应该乍样?是这样往后递加吗?

Dim filter As String = ""
Dim txt As String = e.Form.Controls("TextBox1").TEXT
If txt > "" Then
    txt = "\'%" & txt & "%\'"
    Filter = "部门名称 Like " & txt
End If

Dim txt1 As String = e.Form.Controls("TextBox2").TEXT
If txt1 > "" Then
    txt1 = "\'%" & txt1 & "%\'"
    If Filter > "" Then
        Filter = Filter & " and 专业 Like " & txt1
    Else
        Filter = "专业 Like " & txt1
    End If
End If

 

Dim txt2 As String = e.Form.Controls("TextBox3").TEXT
If txt2 > "" Then
    txt2 = "\'%" & txt2 & "%\'"
    If Filter > "" Then
        Filter = Filter & " and 专业 Like " & txt1 & " and 学历 Like " & txt1

    Else
        Filter = "学历 Like " & txt2
    End If
End If


If Filter > "" Then
    Tables("机构").Filter = Filter
End If


--  作者:狐狸爸爸
--  发布时间:2015/10/23 22:57:00
--  

是的。

太多的话,可以参考下面的简化:

 

Dim filter As String = ""
Dim nms1() As String = {"部门名称","专业","学历")
Dim nms1() As String = {"TextBox1","TextBox2","TextBox3")
For i As Integer = 0 To nms1.Length - 1
    Dim txt As String = e.Form.Controls("TextBox1").text
    If txt > "" Then
        If Filter > "" Then
            Filter = Filter & " and "
        End If
        Filter = Filter & nms1(i) & " Like \'%" & txt & "%\'"
    End If
Next
If Filter > "" Then
    Tables("机构").Filter = Filter
End If