A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

When no data report states error



 
 
Thread Tools Display Modes
  #1  
Old July 11th, 2007, 03:14 AM posted to microsoft.public.access.reports
Tom Tripicchio
external usenet poster
 
Posts: 16
Default When no data report states error

When I run a report based on a query and there is no data to report the
report states "error" in the body of the report.

Is there a way for the report to say "nothing to report"? Or something else
other than "error" When people see error they think something is wrong
rather than no data or nothing to report.

Thanks, Tom


  #2  
Old July 11th, 2007, 04:01 AM posted to microsoft.public.access.reports
Rob Parker
external usenet poster
 
Posts: 701
Default When no data report states error

Hi Tom,

The standard way of handling this is to use code such as this in the
report's On No Data event to prevent the report opening at all:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data to report"
Cancel = True
End Sub

If you are opening the report from code in another form, via a
DoCmd.OpenReport statement, you will need to add error handling to trap the
Cancel event which this code generates. It can be as simple as

Private Sub YourExistingProcedureName()
On Error GoTo ErrorHandler
...
... existing code here
...

Exit Sub
ErrorHandler:
If Err.Number = 2501 Then Resume Next
End Sub

HTH,

Rob

"Tom Tripicchio" wrote in message
...
When I run a report based on a query and there is no data to report the
report states "error" in the body of the report.

Is there a way for the report to say "nothing to report"? Or something
else other than "error" When people see error they think something is
wrong rather than no data or nothing to report.

Thanks, Tom




  #3  
Old July 11th, 2007, 03:38 PM posted to microsoft.public.access.reports
Tom Tripicchio
external usenet poster
 
Posts: 16
Default When no data report states error

Rob, thanks for information. The no data command works great.

I think I would like to carry this further. I have 3 daily reports per
company. Lets say 10 different companies. I run these reports from a macro
(each company has their own macro) and they get emailed directly to the
company via the send object command.

If I use the no data command it stills creates a report to be emailed. Is
there a way for the report not to be emailed if there is no data?

Thanks for your help.

Tom



"Rob Parker" wrote in message
...
Hi Tom,

The standard way of handling this is to use code such as this in the
report's On No Data event to prevent the report opening at all:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data to report"
Cancel = True
End Sub

If you are opening the report from code in another form, via a
DoCmd.OpenReport statement, you will need to add error handling to trap
the Cancel event which this code generates. It can be as simple as

Private Sub YourExistingProcedureName()
On Error GoTo ErrorHandler
...
... existing code here
...

Exit Sub
ErrorHandler:
If Err.Number = 2501 Then Resume Next
End Sub

HTH,

Rob

"Tom Tripicchio" wrote in message
...
When I run a report based on a query and there is no data to report the
report states "error" in the body of the report.

Is there a way for the report to say "nothing to report"? Or something
else other than "error" When people see error they think something is
wrong rather than no data or nothing to report.

Thanks, Tom






  #4  
Old July 12th, 2007, 05:11 AM posted to microsoft.public.access.reports
Rob Parker
external usenet poster
 
Posts: 701
Default When no data report states error

Hi Tom,

Sorry, I never use macros, so I don't know how/whether they offer any
conditional execution depending on error codes (I suspect they probably do).
If they do, you would use the Cancel error code (2501) from the report's On
No Data event to stop the SendObject action.

If you mean VBA code, rather than an actual macro, then one way of doing
this would be to put then DoCmd.SendObject statement in an If statement
which checks a flag set in the error handler after opening the report. The
code outline would be:

Private Sub YourExistingProcedureName()
Dim blnReportHasData as Boolean

On Error GoTo ErrorHandler
...
blnReportHasData = True
DoCmd.OpenReport ....
If blnReportHasData Then
DoCmd.SendObject ...
End If
...
Exit Sub
ErrorHandler:
If Err.Number = 2501 Then
blnReportHasData = False
Resume Next
End If
End Sub

You can't test for Err.Number in the If statement, since the Resume Next in
the error handler clears the error condition (ie. resets Err.Number to 0);
that's why I declare a variable for the flag (blnReportHasData) to use in
the If statement. Alternatively, you could remove all error handling and
then test for Err.Number in the main body of the code:

If Err.Number 2501 Then Docmd.SendObject ...


If you want advice on macro execution, I suggest you post a new question,
with a different (more appropriate) subject line.

HTH,

Rob

"Tom Tripicchio" wrote in message
...
Rob, thanks for information. The no data command works great.

I think I would like to carry this further. I have 3 daily reports per
company. Lets say 10 different companies. I run these reports from a macro
(each company has their own macro) and they get emailed directly to the
company via the send object command.

If I use the no data command it stills creates a report to be emailed. Is
there a way for the report not to be emailed if there is no data?

Thanks for your help.

Tom



"Rob Parker" wrote in
message ...
Hi Tom,

The standard way of handling this is to use code such as this in the
report's On No Data event to prevent the report opening at all:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data to report"
Cancel = True
End Sub

If you are opening the report from code in another form, via a
DoCmd.OpenReport statement, you will need to add error handling to trap
the Cancel event which this code generates. It can be as simple as

Private Sub YourExistingProcedureName()
On Error GoTo ErrorHandler
...
... existing code here
...

Exit Sub
ErrorHandler:
If Err.Number = 2501 Then Resume Next
End Sub

HTH,

Rob

"Tom Tripicchio" wrote in message
...
When I run a report based on a query and there is no data to report the
report states "error" in the body of the report.

Is there a way for the report to say "nothing to report"? Or something
else other than "error" When people see error they think something is
wrong rather than no data or nothing to report.

Thanks, Tom








 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:42 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.