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!

Formula mis-Firing

Status
Not open for further replies.

Deleco

Programmer
Feb 25, 2002
109
GB

I use this formula in my report

Code:
NumberVar lPartDays;
StringVar sDayAss;
StringVar sTemp;

sTemp:="ppppp";

If sDayAss = {TBLASSESSOR.STRKNOWNAS} then
     lPartDays:=0
else
     lPartDays:={@WorkDays};

sDayAss := {TBLASSESSOR.STRKNOWNAS};

lPartDays

This Formula is supposed only give me {@WorkDays} if it is a new person. When i run the report for the first time it gives me the wrong answer, the answer is inflated as it appears that it has given me {@WorkDays} all the time ignoring the formula.

You will see in the formula that there is a variable (sTemp) that does nothing, if after i have run the report and have the wrong answer i go into this formula and change this variable. Then when the formula is saved and closed and the report is viewable again then the formula field displays the correct answer.

As you can imagine this is very annoying. Has anyone experienced this kind of thing before? Can anyone give me any help?

Please note i have tried to use the Previous function but using this it will not allow me to have a summary field using SUM to add up all the values.

Any assistance would be appreciated

Deleco
 
It's very strange that adjusting a dummy variable should have the effect you say.

If you seize control of the formula processing time by placing WhilePrintingRecords at the beginning and also comment out the sTemp line, what is the effect?

Naith
 
Since you are not assigning any value to sDaysAss, I don't think it is even relevant to the formula. Why not remove it and use the following

Code:
If isnull({TBLASSESSOR.STRKNOWNAS}) or  {TBLASSESSOR.STRKNOWNAS} = "" then
     lPartDays:=0
else
     lPartDays:={@WorkDays};

It would also be helpful if you posted the details of @WorkDays

-LW
 
I do set sDayAss at the bottom of the function. I want this Var to be kept so it can be checked against the previous detail line.

Also the details of @WorkDays is un-important because if i change the @Workdays to 1 then i still have the problem.

Deleco
 
Below is the what i am trying to do

Code:
Assessor	Grade	WorkDays	RealWorkDays

Dean		LA	1		1
Dean		SA	1		0
Dean		HJ	1		0
Peter		UI	3		3
Peter		SA	3		0
Peter		HG	3		0
Harry		SA	1		1
HArry		RE	1		0

Totals			14		5

As you can see I have Assessors who can have multiple Grades.

This is the problem. Because they have multiple Grades the WorkDays is repeated on each detail line. When this is then summarised it gives a inflated false result.

To get round this I wrote the initial formula in the post RealWorkDays. What this does is set the value to 0 if the WorkDays for the Assessor have already been counted. Therefore when this field is summarised it will give me the desired result.

I might be going about this completely the wrong way... someone please let me know if you have any ideas.

Deleco
 
Did you insert WhilePrintingRecords, like I said?
 
Naith,

Yes i did try that. If i do that then the report will not let me do a summary on the field. The summary is what i want to see. At the end i want to hide all the details and just show the summary to the user.

The message i get from the report is
"A summary has been specified on a non-recurring field."

Deleco
 
Well, there are a few ways you can achieve this. But you're going to have to sacrifice either using the Next/Previous functions, or the auto-summary.

As it's less effort to do the latter, that's what I would do in your position.
Code:
WhilePrintingRecords;
NumberVar Part;
NumberVar PartTotal;

If OnFirstRecord
Then Part := {@WorkDays}
Else
If {TBLASSESSOR.STRKNOWNAS} = Previous({TBLASSESSOR.STRKNOWNAS})
Then Part := 0
Else Part := {@WorkDays};

PartTotal := PartTotal + Part;

Part;
Insert
Code:
WhilePrintingRecords;
NumberVar PartTotal;
in your report/page/group footer. If it's either of the last two, remember to reset the PageTotal to zero in the corresponding header.

Naith
 
Naith,

Thanks very much for your assistance. Didn't know you did not have to use the system summary.

Cheers


Deleco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top