Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: Please help - error in formula Post Reply Post New Topic
Page  of 2 Next >>
Author Message
j_heller1
Newbie
Newbie


Joined: 24 Sep 2009
Online Status: Offline
Posts: 8
Quote j_heller1 Replybullet Topic: Please help - error in formula
    Posted: 28 Sep 2009 at 6:16am
I am getting an error in a formula, "Error in formula: A string is required here. ", in specifc daata-related situation of the report. The report uses a subreport. The subreport has some conditions in the sections, which control which sections show up.  The error is happening in the subreport, and it happens regardless of which database field is used in the formula, just put any string field (or any field) and no other code, and get the error. Also there are several formulas, if I remove the one getting error, it happens on the next one. But only when this section should have been suppressed. AND this only happens if this is the condion of the first record in the main report. If another record is first, which causes the subreport to display different section, the record that caused the error (i know it is the one because I also run the report with just the one record and it gets error) works fine as the second record. In other words, I have 2 datasets, tied together by a key field. The main report uses the primary key data, and the subreport uses the dependant key data. If I just reverse the order of the first two records in the first dataset, the report runs without error.
I am using Crystal reports .NET for VS 2005 with SP1 of CR and SP1 of VS 2005 installed.
Any ideas?
Puzzled in NJ


Edited by j_heller1 - 28 Sep 2009 at 12:23pm
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 28 Sep 2009 at 12:43pm
Hmmm....I dont know what you have tried.So I will mention some of the obvious. When you change the records and the report runs the presentation of the data must be different. Look at the changes.
 
Since you have not offered a specific formula as the one failing, I am taking that to mean you are not sure which one is the problem.
 
The other things are to use specific data typing in the formulas, to insure things are strings where they need to be. Look at your conditional and suppressing formulas to make sure you have strings used where necessary. Sometimes nulls will create these problems and its quite easy to miss dealing with null values correctly.
 
You should be able to 'force feed' the values that are failing to each of the formulas to see where it is failing.
 
Finally, always keep in mind the multi-pass system that Crystal uses to generate a report. I went through a similar frustration last week because I failed to set a default value for an empty string. The value was there but not at the right time for the report. You think I would have learned better by now but its apparent I have not. Its impossible for me to bill a client for the developer being....so after wasting too much time troubleshooting, I had that 'duh' moment.
 
Hope there is something here that is useful.
 
Regards,
 
John W.
 
 
IP IP Logged
j_heller1
Newbie
Newbie


Joined: 24 Sep 2009
Online Status: Offline
Posts: 8
Quote j_heller1 Replybullet Posted: 28 Sep 2009 at 12:51pm
Hi John:
Thanks for your reply.
As for the formula itself, initially there was some logic in it, but now i have srtripped out logic and it is simply the database field itself. If I remove the formula entirely from the report, it just gets same error on the next formula.
Also since I cannot actually get the report to print in the one order of records,  I cannot compare outputs.
It seems to me that in the ome case the there is no record (which is the case) but in that case the section should be suppressed anyway.
Maybe it has to do with the order that the section suppression formula and the formulas in the section are evaluated?
Any way it seems to me the order of the records should not matter. 
This seems to me to be a bug in CR, but I do not have any workaround.
Is there any way to debug in CR?
Thanks.
Josh 


Edited by j_heller1 - 28 Sep 2009 at 1:32pm
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 28 Sep 2009 at 5:20pm
Not in the way you are used to with VS, no breakpoints, no steps, no watches, etc. Its a far more manual process. If you can get a formula to fail and the formula editor opens the values will show on the left hand side in the tree window. Thats about as much help as CR gives.
 
I would try to isolate the problem. As I recall you have a main report and a subreport. Make sure to test the main report and subreport separately function correctly. If the subreport fails you should be able to key into the problem. If they do then fail when you run them together it is like the manner the info is being passed between the main and subreports. 
 
What you describe seems to infer its not the formulas. Its in the way the information is passed to the formulas. I would again look at the way the CR report creation occurs in the passes. I had the same error message, but not necessarily the same problem. Mine was cause by an empty value being passed. The data was in the database, but the the first pass was not getting the variable loaded at the correct time.  I simply set the value to an empty string and it worked. On the second pass, I was dealing with a grouping issue, the variable was loaded and passed the correct value and all was well. You control some of this if you have not using such things as 'WhilePrintingRecords".
 
You may want to read through the Report Processing Model in the CR help file. You can also look at 'Evaluation Time' in the help file.
 
I hope you can this sorted out, I know how frustrating these can be.
 
Regards,
 
John W.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 29 Sep 2009 at 8:13am
In addition, just because a row is suppressed does not mean that the formula is not called.  I place formulas in suppressed rows all the time, and they execute.
 
Usually, I see this error when you have an if statement, and one half returns a boolean the other a string.
 
Since you report that if you remove the formula the error just moves to another formula, I would be inclined to agree with John that the data in the subreport is not as you expect.  I usually try to display the same data i the main report or with simple formulas to determine where my logic has gone awry...It could be as simple a formula as ISNULL({table.field}).  Since you can't step through, it is a matter of testing the results to see they are what you think they are.
 
HTH
IP IP Logged
j_heller1
Newbie
Newbie


Joined: 24 Sep 2009
Online Status: Offline
Posts: 8
Quote j_heller1 Replybullet Posted: 29 Sep 2009 at 8:49am
Ok, I guess it is time to get into the gory details because I still can't figure out what is wrong.
Here is the error (in the subreport which uses the depentdent key data):
 
Error in formula  <forRepTime>.
'if NOT (IsNull({MyFields.DateField}))Then'
A string is required here.
 
So actually it is failing on the ISNULL check itself!
 
And remember. it all works perfectly if I just make another row in the primary table the first row. This only happens if this type of row, where certain fields may be NULL in the dependant key table, is the first record of the main report.
??????????????????
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 29 Sep 2009 at 10:07am

Hmmm..... I would try to skip the formula and display the value of {MyFields.DateField}.  I know this just causes the error to move elsewhere.  The only other idea is to get the parameters for the subreport that fails and then running the same SQL against the Db and see what you are getting back.  It makes no sense from what you have written, and sometimes CR is like this. 

As I have said before, what I would try is to get CR to display the values that are being used in the subreport, so that you can 'see' the data the same way that CR is.  I know that it is a pain, but there is no faster way to get around an error like this.
 
HTH
IP IP Logged
j_heller1
Newbie
Newbie


Joined: 24 Sep 2009
Online Status: Offline
Posts: 8
Quote j_heller1 Replybullet Posted: 29 Sep 2009 at 10:40am

I use a .net dataset for the report, which contains the two tables used, that I build from data that I get from database. I actually do write out the dataset used by the report to an XML file, just to debug this issue, (if you familiar with .net dataset, you can just create XML file from the dataset).  So I have the data. I have created the file in both cases, the success and failure  case. I do not see anny difference other than the order of the records.



Edited by j_heller1 - 29 Sep 2009 at 10:41am
IP IP Logged
j_heller1
Newbie
Newbie


Joined: 24 Sep 2009
Online Status: Offline
Posts: 8
Quote j_heller1 Replybullet Posted: 29 Sep 2009 at 10:51am
Maybe I should also mention that the report runs from a web application using the CR Engine ReportClass object to actually run the report.

Edited by j_heller1 - 29 Sep 2009 at 10:54am
IP IP Logged
j_heller1
Newbie
Newbie


Joined: 24 Sep 2009
Online Status: Offline
Posts: 8
Quote j_heller1 Replybullet Posted: 29 Sep 2009 at 12:06pm
I decided not to use formula, just added another column to the data table with the field formatted how it needs to be, added it to the report , and voila! no errors. !!!!

Edited by j_heller1 - 29 Sep 2009 at 12:06pm
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.