View Single Post
 
Old 03-03-2012, 02:27 PM
Eri Eri is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Dec 2011
Posts: 6
Eri is on a distinguished road
Default IF statement just generates text "MERGEFIELD" in document - what am I doing wrong?

I have created a new merge document and merged in an Excel spreadsheet. The merge itself works perfectly--no problems, even after adding currency formatting to my fields. But when I try to adjust the display by adding IF statements, I don't get what I need--instead I just get the word "MERGEFIELD". There may be a better way to do this--if so, I'd appreciate help improving my methodology!

I am creating a series of receipts. Each receipt may have one or two line items (as specified in the flat Excel spreadsheet, nothing fancy here), and there may or may not be a discount applied. (I would have liked the Word file to do the math for me instead of importing all the amounts from Excel, but that's another issue entirely, I think!). The area where I am having a problem is that I only want text to be displayed in the discount field if there was, in fact, a discount.

My pseudo code is this:

If the merge field named "Item1_Discount" is not equal to zero, then display it, formatted as US currency with two decimal places. Else, display nothing.

Before I started messing with the IF statement, my code was this, which worked perfectly, except that it displays $0.00 when the discount is zero (it says zero in the spreadsheet, rather than being blank), which is undesirable:

Code:
{ MERGEFIELD "Item1_Discount" \# $0.00 }
I originally tried this:

Code:
{ IF { MERGEFIELD Item1_Discount } <> "0" { MERGEFIELD Item1_Discount \# $0.00 } "" }
That didn't work. It just says "MERGEFIELD" -- I updated the field repeatedly and also saved, closed, and re-opened the document, and even tried printing to see if it was simply not displaying on the screen, but it still just said "MERGEFIELD".

So, thinking that my problem might have to do with the true value having a mergefield in it, I tried to simplify it:

Code:
{ IF { MERGEFIELD Item1_Discount } <> "0" "yes" "no" }
I tried both of the above in a number of variations: with and without quotes around "Item1_Discount" (Word put them in when I created it using insert formula); with and without quotes around the zero, adding and subtracting spaces around the brackets, etc.

Even the simplified code produced the same results--the word "MERGEFIELD" instead of either nothing or the value saved in that field.

I'm guessing that my problem is just a missing/extra space or bracket somewhere, but I can't, for the life of me, figure out what I've done wrong. I consulted with my non-Word-using husband, who can usually find my missing brackets and semi-colons in code in various languages, but he has no idea, either--though he was just going off the many tutorial pages available on the web, and not person experience with Word.

I'm usually the person everyone I know comes to with their Word problems, but this has me completely stumped and feeling rather newbish and quite humbled, as I search in vain for a solution. So I'm hoping someone with far more Word experience than I possess might have a clue and be willing to share it. It will be much appreciated!
Reply With Quote