471,355 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

Print another report on a OnNoData event

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
Mar 21 '07 #1
2 2732
nico5038
3,080 Expert 2GB
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)
Mar 25 '07 #2
ADezii
8,826 Expert 8TB
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
Mar 25 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by ChadDiesel | last post: by
5 posts views Thread by Tony Dong | last post: by
reply views Thread by Fred Zuckerman | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.