Msgbox to display no filtered results

G

Guest

I have a form set up to search my table and it opens another form or report
(based on a checkbox) with the filtered results. The filter is a combination
of a query and a where condition on DoCmd.OpenForm/DoCmd.OpenReport. If the
search terms are too specific and there are no records that match, I want a
message box to pop up and inform the user instead of just opening a blank
form or report. I can't figure out how to do it. Please help!!
 
D

deluxeinformation

Scott said:
I have a form set up to search my table and it opens another form or report
(based on a checkbox) with the filtered results. The filter is a combination
of a query and a where condition on DoCmd.OpenForm/DoCmd.OpenReport. If the
search terms are too specific and there are no records that match, I want a
message box to pop up and inform the user instead of just opening a blank
form or report. I can't figure out how to do it. Please help!!

Set the Visible property of your form or report to False. Then in the
load event of your form put the following:

If Me.RecordSetClone.RecordCount = 0 Then
MsgBox "No records found."
DoCmd.Close
Else
Me.Visible = True
End If

If this is a report, you can simply put the the following in the NoData
event of the report:

MsgBox "No records found."
Cancel = True

Hope this helps.

Bruce
 
D

deluxeinformation

Set the Visible property of your form or report to False. Then in the
load event of your form put the following:

Sorry...this should read "If using a form to display the results, set
the Visible property of the form to False. Then in the load event of
your form put the following:"

Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top