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

Using if then else & instr in Crystal Reports

Status
Not open for further replies.

Craig Wright

Technical User
Dec 20, 2016
17
US
The following formula works according to Crystal's formula checker but when I use it the formula to group in Crystal the error message is: Start position is less than 1 or not an integer

if instr({table_date.balance_accrual},"Accrual","1")>0
then "Accrual Loans"
else "Other"

I will be adding more "if instr"s after the current else in case that influences the answer.

I've searched the instr posts but nothing I've found or tried seems to resolve this issue. I'm guessing it is a relatively basic syntax issue, but I can't find the issue.
 
Try this instead:


if Accrual" IN ({table_date.balance_accrual}
then "Accrual Loans"
else "Other"
 
I appreciate the prompt response! The formula checker responded with "A string is required here" which makes sense since the field {table_date.balance_accrual} is a balance field and not a string field.

So I am checking for text in the name of a balance field - that complicates the formula I'm trying to create. Do you have other suggestions? Thanks!
 
Oops, my post is missing a quote which may be causing the error. Should be:

if "Accrual" IN ({table_date.balance_accrual}
then "Accrual Loans"
else "Other
 
Thanks, Charily, but I had caught the missing " and used it and got the error I mentioned above.

I also just tried:

if "Accrual" IN totext(({table_date.balance_accrual}))
then "Accrual Loans"
else "Other"

and I got no errors but all results were "Other," so while not yielding an error, it isn't finding / yielding a result of "Accrual Loans" *&^%ing syntax, lol. I'm running out of ideas...
 
So what does the data for {table_date.balance_accrual}) actually look like? If it is not a string, then how can you find the word Accrual in it?
 
Kray, you nailed it and I realized it after the fact. I was trying to create a group off of a numeric field by recognizing the name of the field - my mistake! I'll pursue another technique using the above on a text field.

Thanks for the help!
 
Are you trying to do something like this:

IF {table_date.balance_accrual} > 0
then "Accrual Loans"
else "Other
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top