Using COMPARE Function with Multiple Wildcards

J

JASon

I've figured out how to use the COMPARE functionality in a Word merge:

{ COMPARE "{ MERGEFIELD Name }" = "*Smith" } --- Someone with the last name
of Smith

This returns a 1 if true, 0 if false. '*' is the multiple-character
wildcard, and '?' is the single-character wildcard. The problem I'm having
is it doesn't seem to be able to handle 2 '*'s. There is a chance that this
'Smith' could not be at the end and Name would look like "John Smith, Jr." or
"Jane Smith-Harris".

I've tried this:

{ COMPARE "{ MERGEFIELD Name }" = "*Smith*" }

but it always returns 0.

Is there some kind of workaround to this?

Any help is appreciated.

JASon
 
P

Peter Jamieson

I don't know of a way to fix this using fields, except by using a DATABASE
field to do the comparison, which can be complicated.

Other possible approaches are:
a. if your data source allows it, do the comparison using a query and
return an additional field that says whether the comparison succeeded or not
(or return an additional field containing the text you need, if that is
appropriate). This can be done in a number of ways depending on the data
source and your level of access to it. For example, in an Access query you
can use WHERE fieldname LIKE "*Smith*" (old syntax) WHERE fieldname LIKE
"%Smith%"(ANSI-92 syntax) to do this. If the data source can be accessed
using ODBC you will probably be able to use MS Query to set up something
similar, or you could use VBA to set up the query
b. if you are using Word 2002/2003, use VBA and the Word MailMerge events
to run VBA that does the comparison as each record is processed, and takes
appropriate action.

More info. available on these approaches depending on whether you think you
want to try any of them and which one seems likely to meet your needs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top