以文本方式查看主题

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

--  作者:wumingrong1
--  发布时间:2014/12/19 17:12:00
--  [求助] 查询公式问题
我有一个查询按钮公式如下:

vars("查询") = True
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 Then
            If e.Form.Controls(ctl.Name).Text > "" Then
                If c.IsDate Then
                    flt + = " And " & c.Name & " Like #" & e.Form.Controls(ctl.Name).Text & "#"
                ElseIf c.IsString Then
                    flt + = " And " & c.Name & " Like \'%" & e.Form.Controls(ctl.Name).Text.Replace("*", "[*]") & "%\'"
                End If
            End If
        End If
    Next
Next
If flt > "" Then
    flt = flt.SubString(5)

Tables("机房板件端口表").Sort= "业务名称 ,业务序号 "
Else
    MessageBox.Show("请输入查询条件")
End If
Tables("机房板件端口表").Filter = flt
vars("查询") = False


我需要查询的内容有如下格式:

金埔机房[MA5100_2-S9306]_01

这样会查询不到结果,请问我的公式该怎么改?(估计应该是[ ]的问题)

--  作者:有点甜
--  发布时间:2014/12/19 17:23:00
--  

这样改

 

flt + = " And " & c.Name & " Like \'%" & e.Form.Controls(ctl.Name).Text.Replace("[", "@").Replace("]", "#").Replace("@", "[[]").Replace("#", "[]]").Replace("*", "[*]") & "%\'"