View Single Post
  #18   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default Mail merge .. . If Then Else

Hi Peter,

Actually, after removing the 'MERGEFIELD', for use with an ASK field, all those scenarios work for 'XX' as a string, but not as a
bookmark. Tested with:
{QUOTE{ASK PatientCode}"1"
{IF {PatientCode \*Upper} = XX @}"2"
{IF "{PatientCode \*Upper}" = XX @}"3"
{ IF {PatientCode \*Upper} = "XX" @}"4"
{IF "{PatientCode \*Upper}" = "XX" @}}

If you input 'XX' or 'xx' into the 'ASK PatientCode' field, you get '1@2@3@4@' as the output. Anything else returns nothing, which
is as it should be. Mergefields work the same way.

If XX is a bookmark, as in:
{QUOTE{ASK PatientCode}{ASK XX}"1"
{IF {PatientCode \*Upper} = XX @}"2"
{IF "{PatientCode \*Upper}" = XX @}"3"
{ IF {PatientCode \*Upper} = "XX" @}"4"
{IF "{PatientCode \*Upper}" = "XX" @}}
and input 'XX' or 'xx' into the 'ASK PatientCode' field, you get '1@2@34' as the output (ie only the first and second versions
work). Anything else returns nothing.

If you want to use 'XX' as a bookmark, that will work in the 3rd & 4th cases too *if the 'XX' is in a field*, as in:
{QUOTE{ASK PatientCode}{ASK XX}"1"
{IF {PatientCode \*Upper} = {XX} @}"2"
{IF "{PatientCode \*Upper}" = {XX} @}"3"
{ IF {PatientCode \*Upper} = "{XX}" @}"4"
{IF "{PatientCode \*Upper}" = "{XX}" @}}
Now, if you input 'AA' or 'aa' into the 'ASK PatientCode' field, and 'AA' (upper case only) in the 'ASK XX' field, or any other
matching characters, you get '1@2@3@4@' as the output but anything else returns nothing.

Cheers

--
macropod
[MVP - Microsoft Word]


"Peter Jamieson" wrote in message ...
| As I've said before, there are occasions when you have to have at least some
| of the quotes. They may be unusual, but it's good defensive programming to
| use them, although of course, in the absence of a complete specification of
| what fields do, even adding quotes isn't necessarily going to have the
| desired result in all situations. For example, in this case, try inserting a
| bookmark called XX in the document (it can be a regular bookmark or created
| using { SET XX something }, then evaluate
|
| { IF {MERGEFIELD PatientCode \*Upper } = XX @ }
|
| { IF "{MERGEFIELD PatientCode \*Upper }" = XX @ }
|
| { IF {MERGEFIELD PatientCode \*Upper } = "XX" @ }
|
| { IF "{MERGEFIELD PatientCode \*Upper }" = "XX" @ }
|
| I think only the last one works correctly where PatientCode is xx or XX.
|
| That's why I usually advise use of quotes.
|
| Peter Jamieson
| "macropod" wrote in message
| ...
| Hi Doug,
|
| Since there's no spaces in the test condition or true/false results, the
| field works equally well with no quote characters:
| {IF{MERGEFIELD PatientCode \*Upper} = XX @}
|
| Another potential issue is whether the 'PatientCode' field contains
| exactly 'XX' - no more & no less. The OP said "As part of the
| testing i have printed to screen Value X to confirm it contains the data
| for the condition to be met". That's only one 'X'. Or is
| 'Value X' the name of a/the field?
|
| Cheers
|
| --
| macropod
| [MVP - Microsoft Word]
|
|
| "Doug Robbins - Word MVP" wrote in message
| ...
| | Remove the quotation marks from "{ MERGEFIELD PatientCode \*Upper}"
| |
| | --
| | Hope this helps.
| |
| | Please reply to the newsgroup unless you wish to avail yourself of my
| | services on a paid consulting basis.
| |
| | Doug Robbins - Word MVP
| |
| | wrote in message
| | oups.com...
| | On 8 Feb, 16:55, wrote:
| | On 8 Feb, 16:15, "Graham Mayor" wrote:
| |
| |
| |
| |
| |
| | And do test the result of {Mergefield PatientCode} without a
| condition
| | to
| | ensure it reproduces exactly what you think it should reproduce.
| Try
| | also
| |
| | { IF { MERGEFIELD PatientCode \*Upper} = "XX" "@" }
| | --
| |
| | Graham Mayor - Word MVP
| |
| | My web sitewww.gmayor.com
| | Word MVP web sitehttp://word.mvps.org
| |
| |
| | Peter Jamieson wrote:
| | 1. Are all the {} the special field code braces that you can
| insert
| | using ctrl-F9?
| | 2. Is the value definitely XX and not xx, xX etc?
| | 3. Try adding double quotes around the { MERGEFIELD } field, i.e.
| |
| | { IF "{ MERGEFIELD PatientCode }" = "XX" "@" "" }
| |
| | Peter Jamieson
| | wrote in message
| | roups.com...
| | On 8 Feb, 15:33, wrote:
| | Hi - i am having a few problems with the if then else
| conditional
| | statement with word mail merge. The logic that i am looking to
| | implement is if Value X = XX then print @ else print nothing.
| The
| | code is below. Now this seems very simple but for some reason
| | doesnt work and even when the condition is met it does not
| print @.
| | As part of the testing i have printed to screen Value X to
| confirm
| | it contains the data for the condition to be met but it doesnt
| | write the @. { IF { MERGEFIELD PatientCode } = "XX" "@" "" }
| |
| | So the issue i have is that although the condition seems to have
| | been
| | met it does not execute the correct part of the conditional
| | statement. The data being used for the mail merge comes from a
| SQL
| | 2000 SP3a database.- Hide quoted text -
| |
| | - Show quoted text -
| |
| | Hi - thanks for your suggestions - i cant try them at the moment as
| | production is down . With regards word mail merge i dont have any
| | exeperience apart from the hour or so that i have spent looking at
| | this issue (although i have numerous years of development
| experience -
| | somewhat offset by the fact i am now a manager ).
| |
| | In one of the suggestions the code used \*Upper - i pressume that
| | there must be numerous other switches e.g. \*Lower etc. Is there a
| FAQ
| | that describes all these 'switches' - cant seem to find mention of
| | them Word Help.
| |
| | Thanks in advance,
| |
| | CM- Hide quoted text -
| |
| | - Show quoted text -
| |
| |
| | Hi - just tried the suggested fix and it still doesnt work - the code
| | is below;
| |
| | { IF "{ MERGEFIELD PatientCode \*Upper}" = "XX" "@" }
| |
| | Any other suggestions - this is really frustrating because for all
| | intents and purposes it should work. I have tried using the same
| | logic with another merge field and it works fine - could there be
| | anything in particular with this field that might mean that the
| | condition is not being met?
| |
| | Thanks in advance,
| |
| | CM
| |
| |
| |
| |
| |
| |
|
|
|
|