Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Property of closed report

Status
Not open for further replies.

LARiot

Programmer
Feb 7, 2007
232
Hi,

How can the Record Source property of a report (which is closed) be retrieved?

This is to do a count and run the report only if it has records.
Thanks.
 
You would need to open the report in design view, however, why not use DCount to check the number of records in the table, query or modified SQL statement?
 
That's exactly what I'm doing. But I don't want to hard code the report's record source in the VBA because the user has to first choose a report from the combo box.

There has to be a way to get the report's Record Source from VBA without opening the report first.
 
Thanks Remou,

That would make it too complicated and require too much maintenance.

If there isn't a simple way to check a closed report property I might just have VBA open it in Design View then close it. Though it doesn't make for well written code.

Is there a way to kill the report right from the start if the record count is zero?
 
You can use the On No Data event of the report.
 
Thanks Remou,

I used

Code:
Private Sub Report_NoData(Cancel As Integer)

    DoCmd.Close acReport, "Canada"
    
End Sub

but it returns

Run-time error '2585':

This action cannot be carried out while processing a form or report event.

Is there another way to close the report? Also, is there way to close it without specifing a name?

Thanks, I hope I'm not asking for too much.
 
Don't close, Cancel:

Code:
Private Sub Report_NoData(Cancel As Integer)

    cancel=true
    
End Sub

You will get a trappable error, 2501, in your calling code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top