Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2012, 02:27 PM
Eri Eri is offline IF statement just generates text "MERGEFIELD" in document - what am I doing wrong? Windows 7 32bit IF statement just generates text "MERGEFIELD" in document - what am I doing wrong? Office 2010 32bit
Novice
IF statement just generates text "MERGEFIELD" in document - what am I doing wrong?
 
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
  #2  
Old 03-03-2012, 03:03 PM
macropod's Avatar
macropod macropod is offline IF statement just generates text &quot;MERGEFIELD&quot; in document - what am I doing wrong? Windows 7 64bit IF statement just generates text &quot;MERGEFIELD&quot; in document - what am I doing wrong? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,349
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Hi Eri,

You field syntax looks OK, so I suspect the issue may be related to the use of the field braces (ie '{}'). You cannot type these - for manual creation, they must be created in pairs via Ctrl-F9.

In any event, you don't need an IF test - simply format the MERGEFIELD as:
{MERGEFIELD "Item1_Discount" \# "$0.00;-$0.00;"}
or:
{MERGEFIELD "Item1_Discount" \# "$0.00;;"}
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to edit the "Format" and the "show level" of an EXISTING table of content? Jamal NUMAN Word 2 08-14-2011 10:46 AM
IF statement just generates text &quot;MERGEFIELD&quot; in document - what am I doing wrong? Word 2003 document suddenly "locked for editing" by me lisa801 Word 3 07-08-2011 10:11 PM
IF statement just generates text &quot;MERGEFIELD&quot; in document - what am I doing wrong? "Table of content" based on "Normal Style" behavior!!!! Jamal NUMAN Word 4 07-08-2011 04:12 AM
IF statement just generates text &quot;MERGEFIELD&quot; in document - what am I doing wrong? How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM
"Microsoft Excel Application" missing in the "Component Services" on win08 sword.fish Excel 0 02-26-2010 02:09 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 08:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft