I have a shared variable that is coming back into the main report from a subreport and it contains sales rep names that were in the subreport and the subreport uses a different stored procedure than the main report. The main report has a field with sales reps in it as well and this field is delimited by spaces. The field from the subreport is delimited by pipes.
If a salesrep from the field in the subreport is not in the field in the main report then I want to add that rep to the field but if it is already there I want to disregard it. My code does not always work. If I have more than one rep in the field from the subreport and they are both in the main report field then the InStr only works for one of the reps and adds the other rep to the main report field. I have tried to figure this out and am having no luck. I am hoping that someone else with better eyes than mine can help me with this.
Here is my coding and thank you in advance for your help and consideration:
FinalSalesRep has the values: Joe Smith|Henry Ford
{MyTable;1.SalesReps} has the values: Mary Wilson Henry Ford Tom Jones Joe Smith
Shared StringVar FinalSalesRep; // This is a shared variable because it is being returned from a sub report
Stringvar Array RepSplit;
StringVar Rep;
Numbervar p;
NumberVar p2;
RepSplit := Split(FinalSalesRep, "|");
Rep := {MyTable;1.SalesReps};
p := UBound(RepSplit);
for p2 := 1 to p step 1 do
if InStr(Rep,RepSplit[p2]) > 0 then // if the salesman in RepSplit is not in Rep then I want to add it...
Rep := Rep + " " + RepSplit[p2];
Rep; // This is what I want to print, all the sales reps that were already in {MyTable;1.SalesReps} and
// those that were in FinalSalesRep but not already in {MyTable;1.SalesReps}
If a salesrep from the field in the subreport is not in the field in the main report then I want to add that rep to the field but if it is already there I want to disregard it. My code does not always work. If I have more than one rep in the field from the subreport and they are both in the main report field then the InStr only works for one of the reps and adds the other rep to the main report field. I have tried to figure this out and am having no luck. I am hoping that someone else with better eyes than mine can help me with this.
Here is my coding and thank you in advance for your help and consideration:
FinalSalesRep has the values: Joe Smith|Henry Ford
{MyTable;1.SalesReps} has the values: Mary Wilson Henry Ford Tom Jones Joe Smith
Shared StringVar FinalSalesRep; // This is a shared variable because it is being returned from a sub report
Stringvar Array RepSplit;
StringVar Rep;
Numbervar p;
NumberVar p2;
RepSplit := Split(FinalSalesRep, "|");
Rep := {MyTable;1.SalesReps};
p := UBound(RepSplit);
for p2 := 1 to p step 1 do
if InStr(Rep,RepSplit[p2]) > 0 then // if the salesman in RepSplit is not in Rep then I want to add it...
Rep := Rep + " " + RepSplit[p2];
Rep; // This is what I want to print, all the sales reps that were already in {MyTable;1.SalesReps} and
// those that were in FinalSalesRep but not already in {MyTable;1.SalesReps}