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

Report_NoData doesn't work!!

jinalpatel
P: 68
I am opening a report (only one report which is based on four different queries) from a form called frmPostcardPrinting. I would like to close the report if there is no data. I have tried both of these

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3.  
  4. Private Sub Report_Open(Cancel As Integer)
  5.  
  6. Select Case [Forms]![frmPostcardPrinting].Frame0.Value
  7.  
  8. Case 1
  9. Me.RecordSource = "qry_CustomerTypeOption"
  10.  
  11. Case 2
  12. Me.RecordSource = "qry_OrderNumberOption"
  13.  
  14. Case 3
  15. Me.RecordSource = "qry_LoggedDateOption"
  16.  
  17. Case 4
  18. Me.RecordSource = "qry_LocationName"
  19.  
  20. End Select
  21.  
  22.  
  23. End Sub
  24. Private Sub Report_NoData(Cancel As Integer)
  25.     ' Display message to user.
  26.     MsgBox "No data found! Closing report"
  27.  
  28.     ' Close the report.
  29.     Cancel = True
  30.  
  31. End Sub
  32.  
and under the form I have written

Expand|Select|Wrap|Line Numbers
  1. Err_cmdPreview_Click:
  2.  
  3.     If Err.Number = 2501 Then
  4.     Err.Clear
  5.  
  6.     Else
  7.    ' MsgBox "Cannot print postcards as there are no records"
  8.     MsgBox Err.Description
  9.     End If
  10.     Resume Exit_cmdPreview_Click
  11. End Sub

Still the report gets opened with " #Error " showing instead of actual values (as there are no values) on display controls of report.

as there is no error displayed I am confused how should I handle "nodata in report" event

Please help
Dec 15 '08 #1
Share this Question
Share on Google+
4 Replies


RuralGuy
Expert 100+
P: 375
It looks like it should work. Add diagnostic code in the open event to check Me.RecordSource.RecordCount and either MsgBox it or Debug.Print.
Dec 15 '08 #2

ADezii
Expert 5K+
P: 8,638
@jinalpatel
Try a slightly different approach and see what happens, bypassing the NoData() Event. Let me know how you make out:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. Dim strErrMsg As String
  3.  
  4. strErrMsg = "No Data Found, Closing Report!"
  5.  
  6. Select Case [Forms]![frmPostcardPrinting].Frame0.Value
  7.   Case 1
  8.     If DCount("*", "qry_CustomerTypeOption") > 0 Then
  9.       Me.RecordSource = "qry_CustomerTypeOption"
  10.     Else    'No Records Found
  11.       MsgBox strErrMsg
  12.         Cancel = True
  13.     End If
  14.   Case 2
  15.     If DCount("*", "qry_OrderNumberOption") > 0 Then
  16.       Me.RecordSource = "qry_OrderNumberOption"
  17.     Else    'No Records Found
  18.       MsgBox strErrMsg
  19.         Cancel = True
  20.     End If
  21.   Case 3
  22.     If DCount("*", "qry_LoggedDateOption") > 0 Then
  23.       Me.RecordSource = "qry_LoggedDateOption"
  24.     Else    'No Records Found
  25.       MsgBox strErrMsg
  26.         Cancel = True
  27.     End If
  28.   Case 4
  29.     If DCount("*", "qry_LocationName") > 0 Then
  30.       Me.RecordSource = "qry_LocationName"
  31.     Else    'No Records Found
  32.       MsgBox strErrMsg
  33.         Cancel = True
  34.     End If
  35. End Select
  36. End Sub
Dec 15 '08 #3

jinalpatel
P: 68
Thanks ADezii

I got it working. Thanks for your help.

Thanks much..
Dec 16 '08 #4

ADezii
Expert 5K+
P: 8,638
@jinalpatel
You are quite welcome.
Dec 16 '08 #5

Post your reply

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