Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shows message when no matching results 1

Status
Not open for further replies.

Lourry

Technical User
Jul 25, 2003
84
CA
Hello all,

I have a "main" form with a search button on it and when a user click on the search button, it will perform a search and open up a "search results" form and display all the records matching the criteria entered in the "main" form. When a user enters a criteria that doesn't match with any of the existing records, access will just open a blank "search results" form. How can I code it so that when there is no results to return, it will pop up a message box saying "NO MATCH FOUND" with an OK button for the user to click and it will take the user back to the "main" page?

I am using A97 and sql to query the database for matching criteria.

Thanks in advance!

-Lory
 
Either test the return value of a DCount call or test the search form's Recordset.RecordCount value.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
THanks PHV!!

Is it like this:

(I am not sure how to use DCount)....
in the Search_Click() function, add the following:

Code:
if Forms!Search_Results.recordset.recordCount = 0 then
    messagebox
    DoCmd.Closeform "Search"
end if

 
hmmm....the code is not working!

I have two forms, one is "Search" the other is "Search Results".
When I click on the Search button on the "Search" form, it does an SQL query and displays the matching records in a continuous form on the "Search Results" form. However, if no match found, it will display a blank row. How do I write the code to check the recordcount property of the "Search Results" form so that when it is 0, just display a msgbox saying no matching records found and closes the "Search Results" form?

Thanks in advance!

-Lory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top