Archive

Posts Tagged ‘Crystal Reports’

Last Day of Previous Year or First Day of Current Year Calculation in Crystal Reports

January 10, 2012 2 comments

You have a requirement to use the last day of the previous year or the first day of the current year and you don’t want to be hard coding any values into the report.

Very simply.

For Last Day of Previous Year: Create a Formula @PrioYearEnd

date(Year(currentdate)-1,12,31)

 

For First Day of Current Year simply remove the -1 from current date;

date(Year(currentdate),01,01)

 

 

Crystal Reports – No Records Error / Splash Screen

September 16, 2011 Leave a comment

There isn’t much more confusing for an end user than facing a blank screen, with no idea if the screen has loaded, caused an error, or frozen.

When writing crystal reports its important to understand that returning no records is a possibility in a lot of cases and this must be effectively communicated with the user on-screen.

No Records Splash Scren Crystal Reports

No Records Splash Scren Crystal Reports

By default, crystal will not display a no records splash screen or display any error messages. It will simply display your Report Header and page headers and the details will be left blank. This could possibly cause issues for the users as they will no be sure as to whether no records have been returned on if there was some sort of error.

In order to create a crystal Report No Records Splash screen, we need to create a report header which will display a message, should no records be returned by the query.

If you have an existing report header such as our fictional “No. Of Products Per Site Report” –  you simply create a second report header.

Right Click on Report Header in design view and select “insert section below”.

This will create a section called “report header b”. This will contain the message you wish the user to see should no records be returned.

We now want to suppress this section of report so that it only displays when we have no records.

Right Click on our “Report Header b” and select “selection expert”. On the common tab, select the formula editor for Suppress (No Drilldown).

In the formula put the following formula

count({Table1.Field1}) <> 0

Ensure that the suppress checkbox is not checked. See image below.
The red Mark on the forumla box shows that a forumla is enetered in the supression criteria.

Suppress Report Header

This formula will mean that the header will not be displayed if the count of your record field does not equal 0 records.

Page Header.

You will also probably want to hide your column headings if there are no records.

To do this, again go to the “selection expert” and tick the “Suppress (No Drill-Down) checkbox and then click on the formula button and enter.

            if isnull({Table1.Field1}) then true

Page Header Suppression

Page Header Suppression

Thats It!

Now when no records are returned you should be able to see the splash screen telling the user that no records are available.

Remove trailing character in Crystal Reports Formula

This is a relatively straight forward formula to help you remove the last character of a string.

It may be that you wish to remove a period from the end of a field name or an inverted comma. Here we will call our field {DBField1}

 

left({DBField1},len({DBField1})-1)

All we are doing here is using the left function to display all the characters to the left, excluding the last chacter, (which is determineted by the “Len” function)

NOT IN Syntax – Excluding records in Crystal

So you need to exclude a few records from your reports in Crystal.
Perhaps that stray erroneous record in the DB which has never been fixed, or a list or exclude customers for a certain country/state.

If you have a list of values and you want to exclude them, then NOT IN will help you do to this. This can be used for both record selection, or on the suppression criteria for groupings.

So lets say you want to exclude customer ID’s 1512, 1563 and 1765 from appearing in your report.

Simply add in your selection criteria;

NOT({CustomerID} IN [“1512″,”1563″,”1765”])