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

String function in Mail Merge field code...

Status
Not open for further replies.

Inquisitor99

Programmer
Aug 25, 2005
24
US
I am trying to customize a field code in my Word 2000 mail merge document so that the last name displays with an apostrophe + "s" if the last name does not end in "s", or it should display with just an apostrophe if the last name ends in "s".

Example:
If last name ends in "s", as in Simmons, display --> Simmons'
If last name does not end in "s", as in Miller, display --> Miller's


I would like to use the "Right" string function to get the last character of the field "LastName", but I am not having any luck constructing the correct syntax.

Here is the field code without the string function:
{IF {MERGEFIELD LastName} = "s" "'" "'s"

Does anyone know the correct syntax for inserting the "Right" string function, or is there some other way to accomplish this?

Thanks.
 
Is there a substring command in vba to extract a single character?
Is there a length command to discover the length of the string

in vfp i would try the immediate if function, word vba would probable need a if then else construct

iif(subs(len(fieldname)-1,1)="s",fieldname+"'",subs(fieldname,1,len(fieldname)-1)+"'s")
 
Hi Inquisitor,

Word doesn't have a RIGHT field function, but you can work around that for something like this, using wildcards in a simple IF test, as in:
{IF{MERGEFIELD LastName}= "*s" "{MERGEFIELD LastName}'" "{MERGEFIELD LastName}'s"}

Cheers
 
Thanks to all who responded. Macropod, your solution to use the wildcard character was excellent!!! It works very well. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top