Reply
 
Thread Tools Display Modes
  #1   Report Post  
Gary Wu
 
Posts: n/a
Default get mailmerge fields in an IF formula

Hi,

I use Word.MailMerge.Fields to get the set of fields in a document. One
of the fields is an IF formula that contains a couple of mailmerge
fields.

When I loop through the fields, for each field, I use
Word.MailMergeField.Code.Text to get the field code. When it loops to
the IF statement, I get the whole if statement instead of the fields
contained in the if statement as the field code. Is there a way to get
the fields contained in an if statement besides string parsing?
Thanks,
Gary

  #2   Report Post  
Peter Jamieson
 
Posts: n/a
Default

There are at least two collections: fields, and mailmerge fields. Not all
fields are mailmerge fields. If, for example, your IF field looks like

{ IF { MERGEFIELD a } = 0 "{ MERGEFIELD b }" "{ MERGEFIELD c }" }

then your iteration or MailMergeFields would give you

IF  MERGEFIELD a  = 0 " MERGEFIELD b " " MERGEFIELD c "
MERGEFIELD a
MERGEFIELD b
MERGEFIELD c

whereas

{ IF { MERGEFIELD a } = 0 "{ b }" "{ c }" }

would give you

IF  MERGEFIELD a  = 0 " b " " c "
MERGEFIELD a

If you use the ActiveDocument.Fields collection (notice that the Field type
is different from the MailMergeField type), you will see the same result for
the first IF statement but

IF  MERGEFIELD a  = 0 " b " " c "
MERGEFIELD a
b
c

for the second.

Peter Jamieson
"Gary Wu" wrote in message
oups.com...
Hi,

I use Word.MailMerge.Fields to get the set of fields in a document. One
of the fields is an IF formula that contains a couple of mailmerge
fields.

When I loop through the fields, for each field, I use
Word.MailMergeField.Code.Text to get the field code. When it loops to
the IF statement, I get the whole if statement instead of the fields
contained in the if statement as the field code. Is there a way to get
the fields contained in an if statement besides string parsing?
Thanks,
Gary



  #3   Report Post  
Gary Wu
 
Posts: n/a
Default

Peter, thank you very much! With the information you provided, I solved
my problem. What I wanted to achieve is to replace mailmerge fields in
one application with corresponding mailmerge fields in another and at
the same time reserve all the logic in formulas.

So, what I did to achieve that is for each mailmerge field, I check its
type like this

Word.MailMergeField field = ... //a reference to a mailmerge field
if (field.Type == Word.WdFieldType.wdFieldMergeField)
{
//replace the field with a corresponding field.
}

Formulas like an IF statement is of type wdFieldFormula and mailmerge
fields contained in an IF statement is of type wdFieldMergeField. So
with the above code, I can replace only mailmerge fields while keeping
the logic in formulas intact.
Thanks Peter again for your helpful information!

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
Custom Fields in Word 2002 (XP) [email protected] Microsoft Word Help 1 January 20th 05 03:46 AM
Can't find locked fields Ron Ford Mailmerge 0 December 20th 04 05:57 PM
mailmerge more than 256 fields using quatrro as a source afswa Mailmerge 2 December 15th 04 03:55 PM
Using MAILMERGE fields within HYPERLINK fields for Merge to Email Mark V Mailmerge 2 December 4th 04 04:01 PM
posting data from text input fields to fields later in document BOB Microsoft Word Help 1 November 23rd 04 06:19 PM


All times are GMT +1. The time now is 08:31 PM.

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"