你的代码杂乱无章,可以全部删除之,以下面的代码替代。
Function Allfilter()
Dim strWhere As String
Dim ctls As Controls
Dim ctl As Control
Dim str As String
strWhere = "True"
If IsNull(Me.Text3.Value) = False Then
strWhere = strWhere & " AND [设备名称]= '" & Me.Text3.Value & "'"
If IsNull(Me.Text5.Value) = False Then
Set ctls = Me.曙采招待所光交箱资料.Form.Controls
For Each ctl In ctls
If ctl.ControlType <> acLabel Then
If ctl.Name <> "设备名称" Then
str = str & "[" & ctl.Name & "] & "
End If
End If
Next ctl
str = Left(str, Len(str) - 3)
strWhere = strWhere & " AND (" & str & " Like '*" & Me.Text5.Value & "*')"
MsgBox strWhere
End If
End If
Me.曙采招待所光交箱资料.Form.Filter = strWhere
Me.曙采招待所光交箱资料.Form.FilterOn = True
End Function
Private Sub Text3_AfterUpdate()
Call Allfilter
End Sub
Private Sub 查询_Click()
Select Case Me.查询.Caption
Case "返回"
Me.Text5.Value = Null
Me.查询.Caption = "查询"
Case "查询"
Me.查询.Caption = "返回"
End Select
Call Allfilter
End Sub