cancel
Showing results for 
Search instead for 
Did you mean: 

A number is required here... error attempting dynamic label

Former Member
0 Kudos

I am trying to create a report where I am looking at a rolling 13 months worth of data and have used a formula field that uses a select case formula based on the number of the current date's month. Each case has if statements similar to this referencing each month: if (Month({BUG.BG_DETECTION_DATE}) = Month(CurrentDate)-1 and Year({BUG.BG_DETECTION_DATE}) = Year(CurrentDate)) then 1 [this if statement corresponds to just the prior month]

Instead of the "then 1" meaning month ago, is there a way I can get it to say, dynamically, "Aug 2008" or "Jul 2008"? I tried to add " then 'Aug '&Year(CurrentDate) " but it comes up with an error saying "A number is required here" and the error references the if at the beginning. I also tried to change the rest of the if statements to a similar then clause, but to no avail. I figured with the concatenate, &, it would work, but can't get it figured out. I am using a cross-tab to display the data from 1 to 13 in the rows and just the count in the column.

What other functions can I try?

Thank you

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

great help

Former Member
0 Kudos

Hi Reid

follow theses steps:

1. Declare a variable in your formula as:

numbervar returnval;

2. Now write the code as you want just with one thing to assign the value returned to the variable as follows:

if (Month({BUG.BG_DETECTION_DATE}) = Month(CurrentDate)-1 and Year({BUG.BG_DETECTION_DATE}) = Year(CurrentDate)) then returnval:=1

This should be done for all the numbers between 1 to 13.

3. Now write another if statement as:

if returnval = 1 then "Jan " &Year(CurrentDate)

else if returnval = 2 then "Feb "&Year(CurrentDate)

and so on.

This is the safe way to do that.

If you are getting an error as number required here that means you are trying to return different data types at different if else ladder as:

if (Month({BUG.BG_DETECTION_DATE}) = Month(CurrentDate)-1 and Year({BUG.BG_DETECTION_DATE}) = Year(CurrentDate)) then returnval:=1

else if (Month({BUG.BG_DETECTION_DATE}) = Month(CurrentDate)-2 and Year({BUG.BG_DETECTION_DATE}) = Year(CurrentDate)) then returnval:= "Feb" & year(currentdate)

which is not acceptable. You should return a single datatype throughout the whole if statement as:

if (Month({BUG.BG_DETECTION_DATE}) = Month(CurrentDate)-1 and Year({BUG.BG_DETECTION_DATE}) = Year(CurrentDate)) then returnval:= "Jan" & year(currentdate)

else if (Month({BUG.BG_DETECTION_DATE}) = Month(CurrentDate)-2 and Year({BUG.BG_DETECTION_DATE}) = Year(CurrentDate)) then returnval:= "Feb" & year(currentdate)

If you get any syntax error in this then just update this thread with the code you have and I will reply accrodingly.

Regards

Nikhil

Former Member
0 Kudos

Not sure what you are talking about in your reply. Could you provide an example of what you are talking about? I am a newbie to Crystal Reports. Thank you. Reid

Former Member
0 Kudos

Hi Reid

You can set a number variable at the top of this code and

assign that variable to the number that you want this if statement to return.

Write one if statement after the first if statement which returns the values based on the variable value.

hope this helps.

Regards

Nikhil