Closing a report if no data

realnine

Registered User.
Local time
Today, 18:41
Joined
Jun 10, 2003
Messages
40
I did a search with my question and found no solutions that work. I have a report that lists and counts the jobs and amtBilled in the currenet month. The first day of the month there are no jobs listed in the querry. The report writer (print preview view) in the details footer gives err on all the Sum and count calculations. The details section is blank. This freaks the user out because they think something serious it worng.

I am able to display a message box in the report properties-event-on nodata
=MsgBox("No Data Entered",0,"No Data Entered")

After the user clicks OK the form appears with the err in all the footer fields. How can I close the form after the No Data Entered mesage with out it loading in the print preview.

Thanks
 
Real,

In the NoData event:

Code:
MsgBox("There is no matching data")
DoCmd.Close

Wayne
 
Wayne,
Thanks for your response,
I tried that code before posting for help. It has the following results

Runtime error 2585
This action can not be carried out while processing a from or report event.

Is there some other way of aborting a report?
 
Rich said:
Post the code behind your report

Rich,
I don't understand "behind your report" I am using the report properties-event-on no data.

I thinkI need some code something like this

If querry field is null Then
MsgBox "No Data"
DoCmd.Close
End If

I am not that proficient in writhing VB code.
 
If querry field is null Then

Is this a parameter query you are baseing the report off of? Do they need to make a selection or enter something on a form, then click a cmd button to open the report, or do they just select a report from a menu?
How the report is opened can play a big role in stopping it as well. If you go to the properties of the report you should be able to do as WayneRyan said, but try adding the line DoCmd.SetWarnings = False at the begining and True at the end and see if that ends the message.
 
Thanks Everyone for your help.

I stumbled into a solution. Here is the code I put into the
Form-Properties-Event-On No Data

Private Sub Report_NoData(Cancel As Integer)
MsgBox ("No Tows Entered for this month")
DoCmd.CancelEvent
End Sub

I replaced the DoCmd.Close as suggested by Wayne with DoCmd.CancelEvent and it works just the way I want. The report is called from a command button on the main form. If there is no data in the supporting querry the message is displayed and the a click takes the user back to the main form.
 

Users who are viewing this thread

Back
Top Bottom