Checking for NoData in Report

  • Thread starter Thread starter Richard Keeves
  • Start date Start date
R

Richard Keeves

I'm trying to perform a check to see if data exists in a
report. When I execute the code to open the report, it
works fine, however, when I add in the If statement
checking for NoData, I get the error: "Run-time
error '2451'. The report name 'Monthly Branch Report' you
entered is misspelled or refers to a report that isn't
open or does not exist."

here's the code snippet:

DoCmd.OpenReport "Monthly Branch Report",
acViewNormal, , "[brancd]=" & rst!Branch

If Reports![Monthly Branch Report].NoData = False Then
FileCopy strSourceFile, strDestFile
End If

Any suggestions? Thanks.
 
The code is probably running before the report has a chance to open. Why not use the
OnNoData event of the report to do this?
 
Richard said:
I'm trying to perform a check to see if data exists in a
report. When I execute the code to open the report, it
works fine, however, when I add in the If statement
checking for NoData, I get the error: "Run-time
error '2451'. The report name 'Monthly Branch Report' you
entered is misspelled or refers to a report that isn't
open or does not exist."

here's the code snippet:

DoCmd.OpenReport "Monthly Branch Report",
acViewNormal, , "[brancd]=" & rst!Branch

If Reports![Monthly Branch Report].NoData = False Then
FileCopy strSourceFile, strDestFile
End If

I think that should be:

If Reports![Monthly Branch Report].HasData = True Then
 
I tried it..I still get the error

-----Original Message-----
Richard said:
I'm trying to perform a check to see if data exists in a
report. When I execute the code to open the report, it
works fine, however, when I add in the If statement
checking for NoData, I get the error: "Run-time
error '2451'. The report name 'Monthly Branch Report' you
entered is misspelled or refers to a report that isn't
open or does not exist."

here's the code snippet:

DoCmd.OpenReport "Monthly Branch Report",
acViewNormal, , "[brancd]=" & rst!Branch

If Reports![Monthly Branch Report].NoData = False Then
FileCopy strSourceFile, strDestFile
End If

I think that should be:

If Reports![Monthly Branch Report].HasData = True Then
 
Richard said:
I tried it..I still get the error

I'm inclined to think Wayne has put his finger on the
problem. Use the report's NoData event to Cancel the
report. Then your form can trap error 2501 to detect when
the report is canceled.
 
Back
Top