Checking for NoData in Report

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.
 
W

Wayne Morgan

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?
 
M

Marshall Barton

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
 
R

Richard Keeves

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
 
M

Marshall Barton

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top