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

Add " " if Preferred Name is not null

Status
Not open for further replies.

tripleblessed

Technical User
Feb 4, 2006
14
US
Hi,
In my report, I publish each person's Last name, First name, MI, Suffix, Preferred Name, and Class Year. I would like to add quotes around the Preferred Name if the field is not null (if they have a nickname they prefer). Here's an example: Adams, Jeffrey M. "Jeff" '86

How do I add the quotes to my statement:
=IIf(((Trim([Publish])="H" Or Trim([Publish])="B" Or Trim([Publish])="W") And Trim([Last Name])<>""),UCase([Last Name]) & ", " & UCase([First Name]) & " " & UCase([MI]) & " " & UCase([Suffix]) & " " & UCase([Preferred Name]) & " '" & Right([Class Year],2),"")

Thanks for your help!
 
I believe this will do it...
Code:
=IIf(((Trim([Publish])="H" Or Trim([Publish])="B" Or Trim([Publish])="W") And Trim([Last Name])<>""),UCase([Last Name]) & ", " & UCase([First Name]) & " " & UCase([MI]) & "  " & UCase([Suffix]) & "  """ & UCase([Preferred Name]) & """  '" & Right([Class Year],2),"")

[pc2]
 
Thanks, mp9 for the start of it. It did give me quotes around the nickname but unfortunately, it left " " for those people that don't have nicknames. Do you think I need some type of If statement and where would I put it?
Thanks again for your help!
 
Untested:
Code:
=IIf(((Trim([Publish])="H" Or Trim([Publish])="B" Or Trim([Publish])="W") And Trim([Last Name])<>""),UCase([Last Name]) & ", " & UCase([First Name]) & " " & UCase([MI]) & "  " & UCase([Suffix]) & IIF(Len([Preferred Name])>0,"  """ & UCase([Preferred Name]) & """  '"," '") & Right([Class Year],2),"")

[pc2]
 
That worked great - thank you! Now I've tried to use what you wrote to apply it to my next part but I'm getting an error. It's a similar situation - add an x before the Work Ext if the person has an extention. Please tell me what's wrong with my expression (and I apologize if I'm totally offbase - I'm a newbie!) I think I'm all mixed up with my quotes and commas.
ORIGNAL expression (without x before Work Ext):
=IIf((((Trim([Publish])="W" Or Trim([Publish])="B")) And Trim([Work Phone])<>"")," W: " & [Work Phone] & " " & [Work Ext],"")

MY TRY:
=IIf((((Trim([Publish])="W" Or Trim([Publish])="B")) And Trim([Work Phone])<>"")," W: " & [Work Phone] & IIf(Len([Work Ext])>0," "x" & ([Work Ext]) & "," "),"")

Thanks again for your help!
 
I got it!!! I just had to play around with it some more.
Thanks again for all of your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top