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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date error on formula 1

Status
Not open for further replies.

Jonesxx

Technical User
Jul 14, 2004
71
GB
Hi,

I am currently using Crystal v 8.5 to run a report (which somebody else wrote) which consists of various sub reports,

One of the sub reports uses the formula:
NumberVar StartMonth := if Month(CurrentDate) + 2 = 13 then 1 else Month(CurrentDate) + 2;
"Forecasts For Month " + ToText(Date(Year(CurrentDate), StartMonth, 1), "MMMM")

However the following error appears: ‘A month number must be between 1 and 12’

The other sub report uses the formula:
{Table.Field} = "A"
and
{Table.Field} } >= Date(LastYr, LastMth, 1)
and
{Table.Field} < Date(Year(PrintDate), Month(Printdate), 1)
and
{Table.Field} = {?Pm-@ActiveUser}
and
{Table.Field} = 'INM'
and
{Table.Field} <> 'CAN'
and
{Table.Field} <> 'RES'

{ContHist.RESULTCODE} <> 'RES'

However the following error appears: ‘Dates must be between year 1 and year 9999’

Any ideas as to what needs fixing regarding the formulas, thank you very much for your help.
 
This looks like it might have been set up for an accounting report where the last day of the year is the 13th month. Is this correct? If so I would look at the underlying data structure to see if something has changed.

Thanks so much!
satinsilhouette
 
For the first issue, the trouble is that 12 + 2 is 14. After the 'else', add
Code:
if Month(CurrentDate) + 2 = 14 then 2 else
Rewriting to use DateAdd would be better, Crystal can take care of all such problems.

For the second issue, I see nothing obviously wrong. But using PrintDate seems strange - Currentdate can be used.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top