By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Print another report on a OnNoData event

P: 1
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
Share this Question
Share on Google+
2 Replies


nico5038
Expert 2.5K+
P: 3,072
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
Expert 5K+
P: 8,634
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.