Print Page | Close Window

Printing employee names

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=16356
Printed Date: 07 May 2024 at 2:19am


Topic: Printing employee names
Posted By: Jakecola
Subject: Printing employee names
Date Posted: 05 May 2012 at 10:50am

I have a problem that maybe someone can offer their expertise toward solving for me.  I’m fairly new to Crystal Reports and need to print the name of two employees at the bottom of a survey form.  The reason for the breakdown is I don’t want to print the employees’ full name. Just the initials so they can be identified only by the staff and not the person receiving the survey form to complete. It's a privacy thing. Here is what I’ve done so far to reach a solution and the problem facing me. The two employee names ‘employee1’ and ‘employee2’ are each in a separate field as follows:

‘employee1’ (Last, First); ‘employee2’ (Last, First)

In formulas, I broke down the fields as follows to reach the result at the bottom of the page for employee1. 

DRV FNAME: stringvar firstname :=split({Forms_Standard_Drivers.DriverName},",")[2]

DRV LNAME:  stringvar lastname :=split({Forms_Standard_Drivers.DriverName},",")[1];

DRV_INIT:  LEFT ({@DRV LNAME}, 3)

DRVF_INIT: LEFT ({@DRV FNAME}, 2)

 Final fields at bottom of report for employee 1

     DRV_INIT     DRVF_INIT

I did the same thing for the second employee, ie:

ATT FNAME:  stringvar firstname :=split({Forms_Standard_Drivers.AttendantName},",")[2] (etc., etc.)

The solution worked fine until there was no name returned in one or the other fields.  This kicked out an array error and printing would not complete.

My question is this:  Can this formula be condensed into one instance and allow for the skipping over the field if it is blank and enter a 0 (zero), n/a or something to avoid the array error? Currently, each of the DRV.. and ATT.. formulas are individual ones.  I’m guessing there is a much more efficient way of achieving this objective and would really, really appreciate your expert guidance.  Thank you.




Replies:
Posted By: lockwelle
Date Posted: 07 May 2012 at 3:31am
you could make a function that you would pass in a value (table.field) and return a string. This way 1) all the logic would be in one place, 2) can correct for empty strings.
 
the function would look something like:
stringvar outs := "";
stringvar fname;
stringvar lname;
if not isnull(inVar) then (
  if instr(inVar, ",") = 0 then (
    outs:=inVar;
   )
  else(
     fname := left(split({Forms_Standard_Drivers.DriverName},",")[2], 3);
     lname :=  left(split({Forms_Standard_Drivers.DriverName},",")[1], 2);
     outs := fname + lname; //or however you want to format it
  )
 
 return outs;   //at least I think it is return
 
inVar would be the input variable defined when setting up the function.
 
HTH
)
 
 


Posted By: Jakecola
Date Posted: 07 May 2012 at 7:57am
Thank you very much. This may seem a really, really dumb question but will the suggested formula affect the database, it's tables or data, in any way? I'm unfamiliar with the command 'input variable' and it's use in the function. I am quite new to Crystal and just want to be safe rather than sorry. If I wasn't very clear before, all I am wanting to do is pull existing names from a record and place the names, in their abbreviated form, at a position on a survey form.   Again, thank you so much for helping me.


Posted By: lockwelle
Date Posted: 07 May 2012 at 9:17am
no, CR will not write to the database, period.  It is read only.
 
you can write a 'Report Customer Function' for your report.  The way I get to it is to Edit a formula, in the left pane at the very top is Report Custom Function.
 
This would allow you to write the formula (now a function) once and to call many times, instead of needing to duplicate the code.
 
HTH


Posted By: Jakecola
Date Posted: 07 May 2012 at 10:54am
Many thanks to you for your generous help and advice. Heck, if we lived close to each other, I'd offer to mow your yard or something. I plan to try the code, as written, later, and I'm excited to see the result; however, I am a newbie and I may have yet another ignorant question to ask. I'm not afraid to try different things to make something work so I will strive to not be more of a pest than I already have been. Your patience with me is most appreciative.

You're the best!

JC


Posted By: Jakecola
Date Posted: 08 May 2012 at 4:01am
I'm still getting the error: A subscript must be between 1 and the size of the array

That was, and continues to be, the returned error. :(


Posted By: lockwelle
Date Posted: 08 May 2012 at 4:58am
ok, then it is off to debugging.  print the field, check if it has a comma
write a formula like;
stringvar array x := split({table.field});
stringvar z := "";
numbervar y;
for y=1 to ubound(x) do(
  z := z+ " " + x[y];
);
z;
 
 
and see what the output is.  if the output is not as expected, then you will need to determine the way around it.
 
the error is telling you that probably [2] is an illegal value, which implies that there is no comma...
 
 
 


Posted By: Jakecola
Date Posted: 16 May 2012 at 10:36am
>> lockwelle

Please forgive me for not advising earlier but your recommendation worked perfectly! I thank you for the tremendous amount of help you've so graciously extended to me as I mulled through this problem. Through suggestion and guidance, you steered me in the direction of a solution and I am truly grateful to you, and for this site!!



Print Page | Close Window