I created a Search form with unbound search fields from 4 different tables and with results appearing in 4 unbound list boxes. Works like a dream. Id like some advice on the proper VBA to add to the Search button On-Click event for a Msgbox to appear when an entry is not found for only the search field containing the search text. In my most recent version, the msgbox runs even when a search result is found and if I search using the other search fields - it's indiscriminate. Ive tried a few variations and searched your website for ideas; here is my most recent attempt:
(FYI, The form name is SearchF, the first search field Im testing is LesseeName, and the results listbox is LesseeList.)
If (Forms!SearchF.LesseeList) = " " Or IsNull(Forms!SearchF.LesseeList) Then MsgBox ("Search entry not found.") End If
Same results using .LesseeList or !LesseeList Thank you.
Kevin Robertson
@Reply 5 years ago
Try this:
If Forms!SearchF!LesseeList.ListCount = 0 Then
MsgBox ("Search entry not found.")
End If
Elaine HeltmanOP
@Reply 5 years ago
Thanks for the quick response, but it didn't work. The MsgBox still runs if a result is returned.
Looks like the problem is your Wh variable. You're not resetting it for each box. Therefore each time it's having more stuff added onto the end of it. Put Wh="" before each If block.
Elaine HeltmanOP
@Reply 5 years ago
Ah, because they're all separate tables, right? I'll try it. Thanks.
Elaine HeltmanOP
@Reply 5 years ago
Yay, it worked, with Kevin's suggestion (thank you!):
If Forms!SearchF!LesseeList.ListCount = 0 Then
MsgBox ("Search entry not found.")
End If
but I had to delete
If Wh = "" Then
MsgBox "Enter at least one search term."
Exit Sub
or it kept popping up.
Now, I'll replicate Kevin's suggestion for each box. Thanks!
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access Search Seminar.