View Single Post
  #20   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,

| Sorry, had to dash earlier and my examples were not quite as I had tested before posting.
| And certainly with the \*Upper, the "quoteless" example works as you say.
|
| But I don't actually get the same results as you describe below either. For example.
|
| 1.
| Yes, that's what I get assuming "nothing" means "1234" :-)

Um, yes - "nothing" means "1234" - Ooops

| 2.
| Here, I don't get 1@2@34 in any circumstances. I wonder why our results are different?

Nor do I now. Curious. Repeated it a number of times before my last post ...

| If PatientCode is xx or XX, and I input nothing into XX, I get 1@2@3@4@,

Even curiouser, but true.This can be rectified by coding the field along the lines of:
{IF "{PatientCode \*Upper}" = {XX} T F} or {IF "{PatientCode \*Upper}" = "{XX}" T F}
but not:
{IF "{PatientCode \*Upper}" = {REF XX} T F} or {IF "{PatientCode \*Upper}" = "{REF XX}" T F}


| However, I also get the same result if
| PatientCode is xx or XX and I input "XX" (without the quotes) into XX.

Which is as expected.

| If PatientCode is xx or XX, and I input anything except blank or XX into the
| XX field, I get 1@234@ , i.e. versions 1 and 4 work OK.

No, the result of the test is False; that means only versions 2 & 3 work in this case.

| If PatientCode is aa, I always get 1234.

Same here, which is what I'd expect.

| 3.
| I get the same

I'm glad.

|
| 4.

OK, so here's a comparison of using the 'XX' bookmark as a plain vanilla 'XX', '{XX}' and '{REF XX}', using the field coded as:
{QUOTE{ASK PatientCode}{ASK XX}
"1"{IF {PatientCode} = XX T F}
"2"{IF "{PatientCode}" = XX T F}
"3"{ IF {PatientCode} = "XX" T F}
"4"{IF "{PatientCode}" = "XX" T F}}
The minor re-coding, to output T/F and reposition the numbers against the corresponding IF tests, has no effect on the correctness
of the results. I also added a few more tests and omitted your incomplete 'q'.

State 'XX' '{XX}' '{REF XX}'
a. PatientCode=xx,XX=xx: TRUE 1T2T3F4F 1T2T3T4T 1T2T3T4T
b. PatientCode=xx,XX=XX: FALSE 1T2F3T4F 1T2F3T4F 1T2F3T4F
c. PatientCode=XX,XX=xx: FALSE 1T2F3F4T 1T2F3T4F 1T2F3T4F
d. PatientCode=XX,XX=XX: TRUE 1T2T3T4T 1T2T3T4T 1T2T3T4T
e. PatientCode=aa,XX=aa: TRUE 1T2T3F4F 1T2T3T4T 1T2T3T4T
f. PatientCode=aa,XX=AA: FALSE 1F2F3F4F 1F2F3F4F 1F2F3F4F
g. PatientCode=AA,XX=aa: FALSE 1F2F3F4F 1F2F3F4F 1F2F3F4F
h. PatientCode=AA,XX=AA: TRUE 1T2T3F4F 1T2T3T4T 1T2T3T4T
i. PatientCode=aa,XX=xx: FALSE 1F2F3F4F 1F2F3F4F 1F2F3F4F
j. PatientCode=aa,XX=XX: FALSE 1F2F3F4F 1F2F3F4F 1F2F3F4F
k. PatientCode=AA,XX=xx: FALSE 1F2F3F4F 1F2F3F4F 1F2F3F4F
l. PatientCode=AA,XX=XX: FALSE 1F2F3F4F 1F2F3F4F 1F2F3F4F
m. PatientCode=xx,XX=aa: FALSE 1T2F3F4F 1T2F3T4F 1T2F3T4F
n. PatientCode=xx,XX=AA: FALSE 1T2F3F4F 1T2F3T4F 1T2F3T4F
o. PatientCode=XX,XX=aa: FALSE 1T2F3F4T 1T2F3T4F 1T2F3T4F
p. PatientCode=XX,XX=AA: FALSE 1T2F3F4T 1T2F3T4F 1T2F3T4F
q.
r. PatientCode="",XX="": TRUE 1F2F3F4F 1T2T3T4T 1F2F3F4F
s. PatientCode=xx,XX="": FALSE 1F2F3F4F 1F2F3F4F 1F2F3F4F
t. PatientCode="",XX=xx: FALSE 1F2F3F4F 1F2F3F4F 1F2F3F4F

For the plain vanilla 'XX', I get the same results as you did.

| Only the fully quoted version correctly compares PatientCode with "XX" every
| time.

My interpretation differs: What the tests show is that only version 2 returned the correct result every time with plain vanilla
'XX'- until we got to test 'r'. Versions 2 and 4 of the REF field coded as '{REF XX}' gave the same results.

My tests also show that only versions 2 and 4 of the REF field coded as '{XX}' returned the correct result every time, including
test 'r'. I have no idea why omitting 'REF' from the field code should make a difference to that test, but it does.

My take on this is that it's easier to remember, and therefore safer in practice, to use quoted REF fields (without the REF) on both
sides of the equation when testing bookmarked strings. As previously discussed, the testing of bookmarked strings against other
strings needs quotes around any test string that has spaces in it, but not around the bookmark. However, since the field works with
or without quotes around the bookmark, and having them makes for consistency with testing bookmarks against each other, I'd have to
endorse putting quotes around everything as the safest way to code an IF field. I guess I should now go and review/update my
'tutorial' documents.

|
| Which is all very well, but may still not result in a solution for the
| original question...

Sadly, all too true. But it's been an interesting exercise in its own right.

Cheers

--
macropod
[MVP - Microsoft Word]