Data filter--No Records Found

  • Thread starter Thread starter Lauren B
  • Start date Start date
L

Lauren B

I have a data filter built into my database for users to search all records.
I have used the following code:

If Len(Trim(Me.TextBox1)) > 0 Then stLinkCriteria = stLinkCriteria &
"[Field1] Like '*" & Me.TextBox1 & "*' AND "
End If

If Len(Trim(stLinkCriteria)) > 0 Then
stLinkCriteria = Left(stLinkCriteria, Len(stLinkCriteria) - 5)
End If

DoCmd.OpenForm "Form2", , , stLinkCriteria
stDocName = "Form2"
stLinkCriteria = ""

End Sub

When a users searches on something that returns no results, they are still
taken to the results form and it is blank. Is there a way to enter code so
that if a user searches on something that is not found, they get a pop-up
that something like "No Records Found" with the option to click "OK".
Ultimately, they will not be taken to the results page at all.

Thank you in advance for any assistance.

LB
 
Try something like:

'strLinkCriteria construction code
...
If DCount("*", "RecordSourceForForm2", strLinkCriteria) = 0 Then
MsgBox "Empty RecordSource for Form2"

Else
DoCmd.OpenForm "Form2", , , stLinkCriteria

End If
 
Back
Top