View Single Post
  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default Using IF to find whether a Merge Field contains a substring

It's going to be a lot easier to achieve what you are after if the data is
converted into a table, which can be done by opening the csv file in Word
and then selecting everything and use the Convert Text to Table item on the
Tables toolbar. Then can use a macro to iterate through the cells in the
column that may or may not contain the string and use the InStr() function
to determine if it is present. What I would do is have the macro add
another column to the table and populate that with the result of the InStr()
function which will be 0 if the string does not exist or something greater
than 0 if it does. Then, if you use that table as the data source for the
merge, you can have the If...then...Else field check on the values that are
in that new column and include the other document if appropriate.

--
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

"Joshua Pangborn" wrote in
message ...
The answer to that has two parts. The initial datasource is a Oracle
Database. I run a process that extracts the data I need and creates a
Comma
Delimited Text file which I use in the merge. I have no control over how
the
Oracle Database generates the text file.
--
- Joshua Pangborn


"Peter Jamieson" wrote:

What is the data source (Access, SQL Server,...)?

Peter Jamieson
"Joshua Pangborn" wrote in
message ...
I am merging some letters, and I have a merge field that lists a number
of
codes separate by new lines. I need to include another document if a
particular code is in the mergefield. I know that you can use IF
MergeField =
"string", but that returns false. I have tried IF MergeField =
"*string*",
but that also returns false. Is there another way to test if a merge
field
contains a string? Thanks. I can provide more information if needed.
--
- Joshua Pangborn