以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  如何实现模糊搜索  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=46404)

--  作者:tanjon
--  发布时间:2014/2/22 17:51:00
--  如何实现模糊搜索
请专家看看以下的代码,能否帮我改成模糊搜索,譬如,F4这一列,有:英语、法语、日语这些词,在相对应的搜索框,输入“英语”,能搜索出相应的条目,但如果只输入“英”,就不能搜索出任何条目,恳请专家帮忙,也请帮忙指出在“帮助文件”里哪里能找到相关的资料。谢谢。

Dim Filter As String
With e.Form.Controls("TextBox1")
    If .Value IsNot Nothing Then
        Filter = "F1= \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("TextBox2")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "F3= \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("TextBox3")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "F5= \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("TextBox4")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "F4= \'" & .Value & "\'"
    End If
End With
If Filter > "" Then
    Tables("全部编制").Filter = Filter
End If

--  作者:lsy
--  发布时间:2014/2/22 18:10:00
--  

将查询文本框的名称与列名称保持一致。

 

Dim flt As String
For Each c As Col In Tables("全部编制").Cols
    For Each ctl As WinForm.Control In e.Form.Controls
        If c.Name = ctl.Name AndAlso e.Form.Controls(ctl.Name).Text > "" Then
            flt + = " And " & c.Name & " Like \'%" & e.Form.Controls(ctl.Name).Text & "%\'"
        End If
    Next
Next
Tables("全部编制").Filter = IIF(flt > "",flt.SubString(5),flt)

[此贴子已经被作者于2014-2-22 18:13:28编辑过]