where to put abort report on nodata

  • Thread starter Thread starter ANDREW SAUNDERS
  • Start date Start date
A

ANDREW SAUNDERS

Guest
I have a form which collects data for various records and up dates a table, this is done by code as you step through various fields.

Upon finishing the data entery, I have a cmd button which updates the table, then runs a report based on a querry, finally it closes the form and returns to the previously opened form which is update.

It all works ok when there is data on the form which valid for the querry.

I want to skip running the report when there is no data to print!
Have tried using the On no Data in the event properties of the report but this produces an error saying that the open report action was canceled
I assume that there is a simple solution which is evading me !
Regards
Andrew
 
I use

Private Sub Report_NoData(Cancel As Integer)
On Error GoTo Err_Report_NoData

MsgBox "There is no data for this report. Canceling report...", vbInformation, "YourAppName"
Cancel = True

Exit_Report_NoData:
Exit Sub

Err_Report_NoData:
MsgBox Err.Description, , "YourAppName"
Resume Exit_Report_NoData


This way the user does't keep pressing the button and comes to you later saying "Hey this thing you created doesn't work" snigger, snigger

Dave
 
thanks both for coming back
I have tried your solution (Oldsoftboss) but I keep getting the same error ie the code tips over when it returns to the code behind the comand button( this updates table, prints report,and updates another form ) on the form.

I think that it is due to the fact that the report has allready been closed in the on no data event of the report
any other views?

regards
Andrew
 
Private Sub Report_NoData(Cancel As Integer)
MsgBox"There is no data"
DoCmd.Close
End Sub
 
I have come across the same problem in the past and the way I got around it was to test for the number of records sitting in the report's recordset source (usually a query) before issuing the docmd.openreport statement.

If the record count is equal to zero, then I pop up a message box indicating that no records were selected for output, then when the message box is closed, I exit the sub.

If the record count is >0 then I run the report as it normally should.

Hope this helps you.

edtab
 
THANKS TO YOU ALL

I have used a combination of ideas and after many aborted methods I have achieved what was needed and have learnt something on the way!!

many thanks

Andrew
 
I too am looking to be able to display a message box when there is no data in a report. But it seems that the nodata event occurs only at the point of formatting a report for printing. So, this does nothing when a user is just previewing the report.

I am looking to have this message occur when a user is trying to preview. How can I do this?
 
works fine in A2K too. I just added code to my database to display a message box telling the user that there was no data and then cancelling the event. I also had to put error 2501 code in my Click event for the open report button.
 
I'm back to this as I'm trying to tie up loose ends in this database. I'm using Access 97.

I tried the code in another report and it works; it wasn't working in the report I was initially testing it in. The first report is just a display of a totals query. Occasionally, there WILL be no totals, and I want to have a message pop up instead of a blank report (only the headers are showing).

Seems like Access doesn't see the blanks as "no data"...?
 

Users who are viewing this thread

Back
Top Bottom