Connecting Tech Pros Worldwide Forums | Help | Site Map

Print another report on a OnNoData event

Newbie
 
Join Date: Mar 2007
Posts: 1
#1: Mar 21 '07
Hi

I currently have the following code attached to a command button on a switchboard form. This is basic Access 2000.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_daily_reports_button_Click()
  2.  
  3. On Error GoTo NoData
  4.  
  5.     DoCmd.OpenReport "Sales Return (TODAY)", acViewNormal
  6.     DoCmd.OpenReport "Sales/Collections (TODAY)", acViewNormal
  7.     DoCmd.OpenReport "SRV Register (TODAY)", acViewNormal
  8.     DoCmd.OpenReport "STPC Voucher Register (TODAY)", acViewNormal
  9.     DoCmd.OpenReport "FIMs issued (today)", acViewNormal
  10.  
  11. NoData:
  12.  
  13. If Err.Number = 2501 Then
  14. Resume Next
  15. End If
  16.  
  17. End Sub
For the first 2 reports, I have another report that will just print a separate report when there are no items to report. I am trying to work out the code needed.

I have tried setting on the report's NoData event to print the other report but the macro stops. Is there a way to refer to the NoData event in the code builder as above?

Prior to the above code builder I have also tried a macro to print all the same reports with a separate macro in the sales return report on the nodata event but that comes with the error "The function Open Report is not available now".

Any ideas will be greatly appreciated.

Thanks

nico5038's Avatar
Moderator
 
Join Date: Nov 2006
Location: The Netherlands
Posts: 2,232
#2: Mar 25 '07

re: Print another report on a OnNoData event


You should check the report's query to return records before triggering the report.

One way is to use a recordset for this, but as I guess you only need to check a specific date, the DLOOKUP() could be an alternative like:
Expand|Select|Wrap|Line Numbers
  1. IF IsNull(DLOOKUP("datefieldname","tablename","datefield=Date()")) then
  2.  
  3. else
  4.  
  5. endif
  6.  
Dlookup() will return Null when nothing is found.

Clear ?

Nic;o)
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#3: Mar 25 '07

re: Print another report on a OnNoData event


Quote:

Originally Posted by airdata

Hi

I currently have the following code attached to a command button on a switchboard form. This is basic Access 2000.

Private Sub Print_daily_reports_button_Click()

On Error GoTo NoData

DoCmd.OpenReport "Sales Return (TODAY)", acViewNormal
DoCmd.OpenReport "Sales/Collections (TODAY)", acViewNormal
DoCmd.OpenReport "SRV Register (TODAY)", acViewNormal
DoCmd.OpenReport "STPC Voucher Register (TODAY)", acViewNormal
DoCmd.OpenReport "FIMs issued (today)", acViewNormal

NoData:

If Err.Number = 2501 Then
Resume Next
End If

End Sub

For the first 2 reports, I have another report that will just print a separate report when there are no items to report. I am trying to work out the code needed.

I have tried setting on the report's NoData event to print the other report but the macro stops. Is there a way to refer to the NoData event in the code builder as above?

Prior to the above code builder I have also tried a macro to print all the same reports with a separate macro in the sales return report on the nodata event but that comes with the error "The function Open Report is not available now".

Any ideas will be greatly appreciated.

Thanks

Nico has the right idea, just substitute you own Parameters:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_daily_reports_button_Click()
  2. On Error GoTo NoData
  3.  
  4. If IsNull(DLookup("datefieldname", "tablename", "datefield=Date()")) Then
  5.   'Print Report for no Data
  6. Else
  7.   DoCmd.OpenReport "Sales Return (TODAY)", acViewNormal
  8. End If
  9.  
  10. If IsNull(DLookup("datefieldname", "tablename", "datefield=Date()")) Then
  11.   'Print Report for no Data
  12. Else
  13.   DoCmd.OpenReport "Sales/Collections (TODAY)", acViewNormal
  14. End If
  15.  
  16. DoCmd.OpenReport "SRV Register (TODAY)", acViewNormal
  17. DoCmd.OpenReport "STPC Voucher Register (TODAY)", acViewNormal
  18. DoCmd.OpenReport "FIMs issued (today)", acViewNormal
  19.  
  20. NoData:
  21.  
  22. If Err.Number = 2501 Then
  23.   Resume Next
  24. End If
  25. End Sub
Reply