0

In Access 2010 I am trying to create a search box for a table of contacts on a form.

Here is my code:

Private Sub Command119_Click()
On Error GoTo Command119_Click_Err

If (Eval("[Forms]![frmTitlePage]![SearchBox] Is Null")) Then
    ' Clear Filter when search box empty
    DoCmd.RunCommand acCmdRemoveFilterSort
End If
' Handle "'s in search
TempVars.Add "strSearch", Replace(Forms!frmTitlePage!SearchBox, """", """""")
' Build the Filter
TempVars.Add "strFilter", "([Last Name] Like "" * " & [TempVars]![strSearch] & " * "" )"
TempVars.Add "strFilter", TempVars!strFilter & " OR ([First Name] Like "" * " & [TempVars]![strSearch] & " * "" )"
DoCmd.ApplyFilter "", TempVars!strFilter, ""
TempVars.Remove "strFilter"
TempVars.Remove "strSearch"


Command119_Click_Exit:
Exit Sub

Command119_Click_Err:
MsgBox Error$
Resume Command119_Click_Exit

End Sub

I am obviously horrible at this coding so any additional help to clean this search tool up would help tremendously.

4

1 に答える 1