|
Henry D. Sy 发表于 2013-4-24 14:05
这样没有搜索出来的就是"我不是人"
不会啊,我是说分别用三个关键字,“我”、“是”、“人”,就可以搜索出来包括这三个关键字的全部记录啊,只是在查询输入窗体是可以用 逗号隔开表示,对这个,todaynew 版主有个很好的实例,应用上我稍稍改了下。
Private Sub 搜索1_Change()
Me.Recalc
Me.搜索1.SelStart = Len(Nz(Me.搜索1.Value, 0))
If IsNull(Me.搜索1.Value) = False Then
Me.fsbKhGL.Form.Filter = F模糊条件("tblKhGL", 搜索1)
Me.fsbKhGL.Form.FilterOn = True
Me.fsbKhGL.Requery
Else
Me.fsbKhGL.Form.Filter = ""
Me.fsbKhGL.Form.FilterOn = False
End If
End Sub
Private Sub 搜索1_DblClick(Cancel As Integer)
搜索1 = Null
Me.fsbKhGL.Form.Filter = ""
Me.fsbKhGL.Form.FilterOn = False
End Sub
Public Function F模糊条件(A源表, B字符串, Optional C1查询字段1_字段2 = "", Optional D操作 = "and")
Dim stWher, stTqCtl
Dim AA, BB, CC, DD, EE, FF, GG, HH, II, JJ
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim UUx, Um, Ui
Dim VVx, Vm, Vi
Dim str
str = B字符串
If IsNull(B字符串) Or B字符串 = "" Then
'无字符串,为全部显示
' F模糊条件 = "1=1"
F模糊条件 = True
Else
If C1查询字段1_字段2 = "" Or IsNull(C1查询字段1_字段2) Then
'默认为表的全部字段
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM [" & A源表 & "]")
For BB = 0 To rs.Fields.Count - 1
CC = rs.Fields(BB).Name
DD = DD & " & '_' & [" & A源表 & "].[" & CC & "]"
Next
rs.Close
Set rs = Nothing
Else
VVx = Split(C1查询字段1_字段2, "_")
Vm = UBound(VVx)
For Vi = 0 To Vm
CC = VVx(Vi)
DD = DD & " & '_' & [" & A源表 & "].[" & CC & "]"
Next
End If
DD = Mid(DD, 10)
str = Replace(str, " ", "_")
str = Replace(str, ",", "_")
str = Replace(str, ",", "_")
str = Replace(str, ".", "_")
str = Replace(str, "。", "_")
str = Replace(str, "-", "_")
UUx = Split(str, "_")
Um = UBound(UUx)
For Ui = 0 To Um
FF = UUx(Ui)
If FF = "" Then
Exit For
Else
If D操作 = "AND" Then
GG = GG & " AND " & DD & " LIKE '*" & FF & "*'"
Else
GG = GG & " OR " & DD & " LIKE '*" & FF & "*'"
End If
End If
Next
F模糊条件 = Mid(GG, 6)
End If
End Function
|
|