Query Result pop-up

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query that searches for previous entries in a employee table and
prints a report if it finds an existing record, i.e. there is an employee by
the name "Smith". How can I get the query to return a message box that says
"No record found" if there are no records, that match the query parameter?
Currently I get a blank report.
 
The usual way of handling this is not to get the query to return a message
box (presumably by code - you can't do it directly), but to use the NoData
event of the report itself. An example from one of my applications is:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There were no credit card orders in this month", vbInformation +
vbOKOnly, msgTitle
Cancel = True
End Sub

If you are opening the report via code, you will get a system message that
the previous action was cancelled. You can supress this by trapping the
error condition as follows:

...
On Error Resume Next
DoCmd.OpenReport "rptCCOrders", acPreview
...

(If you've got other error trapping in place, restore it after opeining the
report.)

HTH,

Rob
 
You can't set the query to do that, but you can set the report to do that, by
adding this code to the OnNoData Property in the report

Msgbox "There is no data"
Cancel = true
 
Back
Top