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

Slice string in Word in mail merged data 1

Status
Not open for further replies.

tigershoot

Programmer
Oct 26, 2005
2
GB
Hello

I am using Word 2000 and I am having difficulty with the following.
I am merging data and one of the fields contains a reference code that is always 8 characters long. What I want to do is use an IF statement and check the last two characters in the string. If they equal 'FM' then the condition is met and extra text then prints in the document.
I can get it to work by trying out the IF statement hard coded with the reference code. But when I try using the RIGHT command to slice the string it does not work. The code will vary in the merged data - some with endings other then FM. Only those ending in FM will get the extra text in their letter. Can anyone give a clue as to the exact syntax required.

I must add that I have never attempted anything like this before and that I am a newbie.
 
Could you post the code that you tried and some sample data?


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hi tigershoot,

You can do this without vba. Given that the reference field "is always 8 characters long", you can use field coding with wildcards in your merge letter to test it:
{IF{MERGEFIELD Reference}= "??????FM" "True Text"}

Cheers
PS: Word doesn't have a 'RIGHT', 'LEFT' or 'MID' field function.
 
Thanks a million - the wildcard did the trick and my document is now behaving perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top