I made a search form. I want to add a message box when there are no results. What would the code be to add a message when the search returned no results?
I know you have to put:
MsgBox "Your search returned no results. Please check the spelling and try again.", vbInformation, "Invalid Search Criterion"
But where would I put this? What would be the statement?
This is my code:
I know you have to put:
MsgBox "Your search returned no results. Please check the spelling and try again.", vbInformation, "Invalid Search Criterion"
But where would I put this? What would be the statement?
This is my code:
Code:
Private Sub btnSearchAccounts_Click()
Dim strWhere As String ' The Criteria String
Dim lngLen As Long ' Length of the criteria string to append to
' Adds LIKE Company field match to the string
If Not IsNull(Me.txtSearchCompany) Then
strWhere = strWhere & " ([Company] Like '" & Me.txtSearchCompany & "*') AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "Please try again.", vbInformation, "Invalid Search Criterion"
Else
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
Debug.Print strWhere
' Apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub