Aug/07
28
Crystal Reports: Display a Message When Report Has No Data
No comments · Posted by Craig Buchanan in Business Objects Enterprise, Crystal Reports, Technique
Often it is desirable to display a message, such as ‘No matching records’, when a report does not contain data. Unfortunately, Crystal Reports does not have a function to easily identify this state.
Fortunately, this functionality can be approximated by building a formula that manually counts the records. This formula, excuted during the report’s ‘WhileReadingRecords’ phase, will increment a Global variable. To work correctly, this formula will need to reside in the report’s Details section.
To build a report that uses this functionality, follow these steps:
- Create a formula named ‘Records’.
- Set the formula’s text to be:
//Excute this formula as records are read into the report
WhileReadingRecords;
//define a variable that is available throughout the 'main' report
Global Numbervar Records;
//increment the variable
Records:=Records+1;
- Place this field in the report’s Details section. Suppress the field by checking ‘Suppress’ check box on the Format Editor’s Common tab.
- Create a new Page Header section by right-clicking the Page Header section and choose ‘Insert Section Below’ from the context menu.
- Right-click the newly-created Page Header and choose ‘Section Expert…’ from the context menu. Check the ‘Underlay Following Sections’ checkbox.
- Click the Conditional-Formula Editory button to the right of the ‘Suppress’ checkbox. Set the formula’s text to:
//If the field isn't null, suppress the section; the field will only be null when
//the report does not contain data.
Not(Isnull({@Records}))
- Add a Text Object to the report containing the desired message. Place the Text Object in the newly-created Page Header section.
- Test the report.
