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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Options when you have null searches

Status
Not open for further replies.

mulligh

Technical User
May 8, 2001
97
US
Hello: When a search returns no records (form based on a query), you get a blank screen. Are there any other options, like having a msg box open or something? I know you can have it display all records if nothing is found, but that's not useful to me.

Thanks.
 
Hi,

I assume that you are opening a new search results form and changing its recordsource with the search query? If so you can create a recordset based on the query and test the recordset's recordcount property like:

'At least one record found
if rst.recordcount > 0 then
docmd.openform "frmSearchresults"
forms!frmSearchResults.recordsource = "qryName" 'or SQl statement
else
msgbox "No records returned from seach"
end if
 
I have a couple of forms that are simular to the above. In your command button or event, you can try the following right after the command that opens the query in question:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No records to display."
Me.RecordSource = "DefaultSource"
End If

Of course you will replace "DefaultSource" with whatever table or query you desire as the record source if the query pulls no records.

Hope this helps. ljprodev@yahoo.com
Professional Development
MS Access Applications
 
Thanks for your replies. I'm a little lost. What I have is a form and the form's record source is a select query which prompts you for a keyword.

Is there a way to pipe the query search results through a form or a better way to do keyword searches in Access?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top