从表单中“全局”搜索表格内容

时间:2017-06-26 16:24:52

标签: access-vba

我正在设计一个表单上的文本框和按钮,我想运行一个“全局”过滤器,只显示我在文本框中输入的文本出现在表格中“馈送”的任何位置的行形式(希望有意义)。下面的代码将返回前两个字段(RIC和P_RIC)的结果,但之后没有任何内容。有人可以指出我正确的方向吗?

Public Sub Global_Search_Click()
DoCmd.OpenForm "Wait", acNormal, , , , , acWindowNormal
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
DoCmd.Hourglass (-1)
Screen.MousePointer = 11
DoCmd.SetWarnings False

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([RIC] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([P_RIC] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([ALT_RIC] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([RIN] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([ALT_RIN] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([RIC_NOMENC] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([PRID] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([HSC] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([EFD] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([EIC] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([ESD] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([LOCATION] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([SERIAL_NUM] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
lngLen = Len(strWhere) - 5
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
Else

If Not IsNull(Me.txtFilterGlobal) Then
strWhere = strWhere & "([WCR_EQUIP] Like ""*" & Me.txtFilterGlobal & "*"") AND "
Screen.MousePointer = 0
If lngLen <= 0 Then Me.Filter = Null
If lngLen > 1 Then strWhere = Left$(strWhere, lngLen)
If lngLen > 1 Then Me.Filter = strWhere
If lngLen > 1 Then Me.FilterOn = True
If lngLen <= 0 Then Me.FilterOn = False
DoCmd.Close acForm, "Wait"
If lngLen > 1 Then Exit Sub
End If

DoCmd.SetWarnings True
If Me.Recordset.RecordCount = 0 Then MsgBox "No results for this search"
DoCmd.Close acForm, "Wait"
DoCmd.Hourglass (-0)
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub

0 个答案:

没有答案