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)
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 作者: sxgaobo 时间: 2013-4-24 18:24 本帖最后由 sxgaobo 于 2013-4-24 18:26 编辑
谢谢各位的关注!
我没说明白,是这样的:
比如筛选条件是:市紫金东路5号24幢
希望下面的记录都被筛选出来
市紫金东路五号二十四幢3单元5层西房
市紫金东街5号24幢5单元6层西房
市紫金东路5号24号楼3单元3层东房 作者: Henry D. Sy 时间: 2013-4-24 18:30