I have a button on a form that gives the user an opportunity to search for a record that contains the address that the user types into an InputBox.
If nothing is found, a MsgBox notifies the user and then closes which returns the user back to the form
What I would like to do is give the user the option to search again if nothing is found instead of them having to click the search button on the form. What would be the best way to accomplish this?
Here's the current code:
Code:
Private Sub SearchByAddress()
Dim S, LN As String
S = InputBox("Enter the address of the property" & vbCrLf & "(partial address search works as well)", "Find A Property by address")
If S = "" Then Exit Sub
LN = Nz(DLookup("PropertyAddress1", "Property_T", "[PropertyAddress1] LIKE ""*" & S & "*"""), "")
If LN = "" Then
MsgBox "That address was not found.", vbInformation, "Search Result"
Exit Sub
Else
DoCmd.OpenForm "ViewProperty_F", , , "[PropertyAddress1] = " & " '" & LN & "'"
Forms!ViewProperty_F.Filter = "PropertyAddress1 LIKE ""*" & S & "*"""
Forms!ViewProperty_F.FilterOn = True
Forms!ViewProperty_F.SearchFilter = "ON"
Forms!ViewProperty_F.SearchFilter.BackColor = vbRed
End If
End Sub