View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] GreenEnvy22@gmail.com is offline
external usenet poster
 
Posts: 2
Default If Then Else with mail merge faulty logic?

On Sep 11, 11:51 am, wrote:
I have a situation where depending on a code from the data source, we
want to insert different text.

I'm having an issue where it seems Words If statement has a flaw. This
is all office 2003 pro.

Here is the line of code:
{If {MERGEFIELD APPEAL } = 90FR12345 "Matches" "Does Not Match"}

And with the code hidden for the appeal field so you can actually see
it:
{If 90CN98765 = 90FR12345 "Matches" "Does Not Match"}

The issue is that it will display "Matches" every time. The example
above clearly should display "Does Not Match". The problem, as near as
I can tell, is that Word can't handle the change from numbers to
letters. All it sees is 90 for both, so it works.
If I change the condition to say 91FR12345 it will then say "Does Not
Match"

I've tried putting quotes around the condition (Word does this
automatically if I use the Add-Field-If..Then..Else function, but
that also does not work.

Anyone have any suggestions to try here? I also would be willing to do
this via VBa, but as far as I can tell I can't access the mail merge
fields from VBa.


I solved my own issue. The problem was Word was assuming the field was
all numeric, so as soon as it encountered a non number it quit.
To solve this, I changed the line to the following:

{If {MERGEFIELD APPEAL \b } = 90FR12345 "Matches" "Does Not Match"}

This works, as Word now treats it as text, not a number.