Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
hbear hbear is offline
external usenet poster
 
Posts: 22
Default tricky IF merge criteria

Is it possible to use the last character of the value in one field as the
criteria in an IF merge statement? To clarify, it would be something like
this: IF last character in "FieldX" is "1", Then "A", Else "B". If this is
possible, I can think of several uses I could put it to in current and future
projects, and I'd love to see what the experts here have to say.

Thanks!

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default tricky IF merge criteria

You should be able to do

{ IF { MERGEFIELD FieldX } = "*1" "A" "B" }

(assuming FieldX is a merge field) but
a. only if the text in MergeX isn't above 128 characters
b. just so you know, you can also use "?" to wildcard a single character
but you can't do a "contains" by using

{ IF { MERGEFIELD FieldX } = "*1*" "A" "B" }

If you're using aa SET field, things may get stuck if the value exceeds 128
characters - i.e. if you do

{ SET X "128 characters.... followed by a 1" }
{ X }
{ IF "{ X }" = "*1" "A" "B" }

Then you get a message "Error! Trailing portion of string too long for
wildcard match."
Then even if you change the SET to

{ SET X "1" } and update all the fields, you may still see that error. { X}
evaluates correctly outside the IF, but if you select the one inside the IF,
right-click and toggle it to see its value, it seems to be stuck in the
state that caused the error. Delete and re-insert { X } and you're OK again.
But maybe you don't need to know that, or it's some quirk on my system. This
is another case where { IF x = "*1" "A" "B" } works better than the { IF
"{ X }" = "*1" "A" "B" } that I normally prefer.

Peter Jamieson

"hbear" wrote in message
...
Is it possible to use the last character of the value in one field as the
criteria in an IF merge statement? To clarify, it would be something like
this: IF last character in "FieldX" is "1", Then "A", Else "B". If this
is
possible, I can think of several uses I could put it to in current and
future
projects, and I'd love to see what the experts here have to say.

Thanks!


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
hbear hbear is offline
external usenet poster
 
Posts: 22
Default tricky IF merge criteria

*1! I could kick myself for missing that one. But there's tons of great
information here. Thanks so much for sharing!

"Peter Jamieson" wrote:

You should be able to do

{ IF { MERGEFIELD FieldX } = "*1" "A" "B" }

(assuming FieldX is a merge field) but
a. only if the text in MergeX isn't above 128 characters
b. just so you know, you can also use "?" to wildcard a single character
but you can't do a "contains" by using

{ IF { MERGEFIELD FieldX } = "*1*" "A" "B" }

If you're using aa SET field, things may get stuck if the value exceeds 128
characters - i.e. if you do

{ SET X "128 characters.... followed by a 1" }
{ X }
{ IF "{ X }" = "*1" "A" "B" }

Then you get a message "Error! Trailing portion of string too long for
wildcard match."
Then even if you change the SET to

{ SET X "1" } and update all the fields, you may still see that error. { X}
evaluates correctly outside the IF, but if you select the one inside the IF,
right-click and toggle it to see its value, it seems to be stuck in the
state that caused the error. Delete and re-insert { X } and you're OK again.
But maybe you don't need to know that, or it's some quirk on my system. This
is another case where { IF x = "*1" "A" "B" } works better than the { IF
"{ X }" = "*1" "A" "B" } that I normally prefer.

Peter Jamieson

"hbear" wrote in message
...
Is it possible to use the last character of the value in one field as the
criteria in an IF merge statement? To clarify, it would be something like
this: IF last character in "FieldX" is "1", Then "A", Else "B". If this
is
possible, I can think of several uses I could put it to in current and
future
projects, and I'd love to see what the experts here have to say.

Thanks!



  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
hbear hbear is offline
external usenet poster
 
Posts: 22
Default tricky IF merge criteria

Peter, This worked wonderfully. Until... I ran into a field with more than
128 characters. Then I got the "Error! Trailing portion..." issue you
mention. I was wondering if it would be possible to test the length of the
field before running the criteria test. My original thought was something
along the lines {IF len{MergefieldX}128 "" "(run criteria test here)"}. I
tried that to no avail, then looked in the field list and chanced across the
NUMCHAR code. The description says it displays the number of characters in
the document, but I wonder if it can be used to test the number of characters
in a field. I've played with it a bit but no luck yet. Any thoughts or
suggestions on this?

Thanks.

"Peter Jamieson" wrote:

You should be able to do

{ IF { MERGEFIELD FieldX } = "*1" "A" "B" }

(assuming FieldX is a merge field) but
a. only if the text in MergeX isn't above 128 characters
b. just so you know, you can also use "?" to wildcard a single character
but you can't do a "contains" by using

{ IF { MERGEFIELD FieldX } = "*1*" "A" "B" }

If you're using aa SET field, things may get stuck if the value exceeds 128
characters - i.e. if you do

{ SET X "128 characters.... followed by a 1" }
{ X }
{ IF "{ X }" = "*1" "A" "B" }

Then you get a message "Error! Trailing portion of string too long for
wildcard match."
Then even if you change the SET to

{ SET X "1" } and update all the fields, you may still see that error. { X}
evaluates correctly outside the IF, but if you select the one inside the IF,
right-click and toggle it to see its value, it seems to be stuck in the
state that caused the error. Delete and re-insert { X } and you're OK again.
But maybe you don't need to know that, or it's some quirk on my system. This
is another case where { IF x = "*1" "A" "B" } works better than the { IF
"{ X }" = "*1" "A" "B" } that I normally prefer.

Peter Jamieson

"hbear" wrote in message
...
Is it possible to use the last character of the value in one field as the
criteria in an IF merge statement? To clarify, it would be something like
this: IF last character in "FieldX" is "1", Then "A", Else "B". If this
is
possible, I can think of several uses I could put it to in current and
future
projects, and I'd love to see what the experts here have to say.

Thanks!



  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default tricky IF merge criteria

That's unfortunate.

No, there's no len() function within the "field language" and NUMCHARS is
just for the total length of the document.

In this case your best bet is to change or process the data source in some
way.

For example, you may be able to use SQL to do the test, but whter you can do
that and how to do it depend on
a. what the data source is (and what you are in a position to do with it)
b. what version of Word

e.g. if the data source is an Access table or query or SQL Server table or
query, you can probably write a a query/view that does the test or selects
the final character of the field into a new column. For example, in Access
you might use right(X,1) to get the last character.

Even if the data source isn't obviously a "database" you may stil be able to
use this kind of SQL by issuing it from Word VBA. However, it is also
possible that you will run into similar restrictions on the lengths of
comparands.

Peter Jamieson
"hbear" wrote in message
...
Peter, This worked wonderfully. Until... I ran into a field with more
than
128 characters. Then I got the "Error! Trailing portion..." issue you
mention. I was wondering if it would be possible to test the length of
the
field before running the criteria test. My original thought was something
along the lines {IF len{MergefieldX}128 "" "(run criteria test here)"}.
I
tried that to no avail, then looked in the field list and chanced across
the
NUMCHAR code. The description says it displays the number of characters
in
the document, but I wonder if it can be used to test the number of
characters
in a field. I've played with it a bit but no luck yet. Any thoughts or
suggestions on this?

Thanks.

"Peter Jamieson" wrote:

You should be able to do

{ IF { MERGEFIELD FieldX } = "*1" "A" "B" }

(assuming FieldX is a merge field) but
a. only if the text in MergeX isn't above 128 characters
b. just so you know, you can also use "?" to wildcard a single character
but you can't do a "contains" by using

{ IF { MERGEFIELD FieldX } = "*1*" "A" "B" }

If you're using aa SET field, things may get stuck if the value exceeds
128
characters - i.e. if you do

{ SET X "128 characters.... followed by a 1" }
{ X }
{ IF "{ X }" = "*1" "A" "B" }

Then you get a message "Error! Trailing portion of string too long for
wildcard match."
Then even if you change the SET to

{ SET X "1" } and update all the fields, you may still see that error.
{ X}
evaluates correctly outside the IF, but if you select the one inside the
IF,
right-click and toggle it to see its value, it seems to be stuck in the
state that caused the error. Delete and re-insert { X } and you're OK
again.
But maybe you don't need to know that, or it's some quirk on my system.
This
is another case where { IF x = "*1" "A" "B" } works better than the { IF
"{ X }" = "*1" "A" "B" } that I normally prefer.

Peter Jamieson

"hbear" wrote in message
...
Is it possible to use the last character of the value in one field as
the
criteria in an IF merge statement? To clarify, it would be something
like
this: IF last character in "FieldX" is "1", Then "A", Else "B". If
this
is
possible, I can think of several uses I could put it to in current and
future
projects, and I'd love to see what the experts here have to say.

Thanks!






  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
hbear hbear is offline
external usenet poster
 
Posts: 22
Default tricky IF merge criteria

The source is an Access database and your suggestion for dealing with the
problem from there worked perfectly. I created a calculated field in the
source query and the merge ran like a dream.
Thanks so much.

all the best!
hb


"Peter Jamieson" wrote:

That's unfortunate.

No, there's no len() function within the "field language" and NUMCHARS is
just for the total length of the document.

In this case your best bet is to change or process the data source in some
way.

For example, you may be able to use SQL to do the test, but whter you can do
that and how to do it depend on
a. what the data source is (and what you are in a position to do with it)
b. what version of Word

e.g. if the data source is an Access table or query or SQL Server table or
query, you can probably write a a query/view that does the test or selects
the final character of the field into a new column. For example, in Access
you might use right(X,1) to get the last character.

Even if the data source isn't obviously a "database" you may stil be able to
use this kind of SQL by issuing it from Word VBA. However, it is also
possible that you will run into similar restrictions on the lengths of
comparands.

Peter Jamieson
"hbear" wrote in message
...
Peter, This worked wonderfully. Until... I ran into a field with more
than
128 characters. Then I got the "Error! Trailing portion..." issue you
mention. I was wondering if it would be possible to test the length of
the
field before running the criteria test. My original thought was something
along the lines {IF len{MergefieldX}128 "" "(run criteria test here)"}.
I
tried that to no avail, then looked in the field list and chanced across
the
NUMCHAR code. The description says it displays the number of characters
in
the document, but I wonder if it can be used to test the number of
characters
in a field. I've played with it a bit but no luck yet. Any thoughts or
suggestions on this?

Thanks.

"Peter Jamieson" wrote:

You should be able to do

{ IF { MERGEFIELD FieldX } = "*1" "A" "B" }

(assuming FieldX is a merge field) but
a. only if the text in MergeX isn't above 128 characters
b. just so you know, you can also use "?" to wildcard a single character
but you can't do a "contains" by using

{ IF { MERGEFIELD FieldX } = "*1*" "A" "B" }

If you're using aa SET field, things may get stuck if the value exceeds
128
characters - i.e. if you do

{ SET X "128 characters.... followed by a 1" }
{ X }
{ IF "{ X }" = "*1" "A" "B" }

Then you get a message "Error! Trailing portion of string too long for
wildcard match."
Then even if you change the SET to

{ SET X "1" } and update all the fields, you may still see that error.
{ X}
evaluates correctly outside the IF, but if you select the one inside the
IF,
right-click and toggle it to see its value, it seems to be stuck in the
state that caused the error. Delete and re-insert { X } and you're OK
again.
But maybe you don't need to know that, or it's some quirk on my system.
This
is another case where { IF x = "*1" "A" "B" } works better than the { IF
"{ X }" = "*1" "A" "B" } that I normally prefer.

Peter Jamieson

"hbear" wrote in message
...
Is it possible to use the last character of the value in one field as
the
criteria in an IF merge statement? To clarify, it would be something
like
this: IF last character in "FieldX" is "1", Then "A", Else "B". If
this
is
possible, I can think of several uses I could put it to in current and
future
projects, and I'd love to see what the experts here have to say.

Thanks!





Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't save merge criteria Csutak40 Mailmerge 3 November 23rd 06 05:35 PM
mail merge selection criteria Barry Osborne Microsoft Word Help 3 November 21st 06 07:45 PM
Allow user to rerun merge using different parameter criteria [email protected] Mailmerge 1 December 19th 05 12:01 PM
merge word with an access query with a like criteria Salli Mailmerge 1 December 1st 05 10:35 PM
888 Word Merge String Criteria Andy Mailmerge 1 July 5th 05 09:03 AM


All times are GMT +1. The time now is 11:24 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"