Inserting merge code into an If...Then statement

  • Thread starter Veteran of the software cycles
  • Start date
V

Veteran of the software cycles

I'm using Word 2003 with an Excel spreadsheet as my data source to create a
merge in a lengthy document. I need an If...Then-type field that will allow
me to have another field code in the Insert This Text area.

Example:

If: "Spouse_Y_N" Is Equal to: "Yes", then insert: [Spouse Name].

Where Spouse Name is also a field pulling from the same Excel spreadsheet.

Any ideas on how I can achieve this?

Thanks in advance.
 
M

macropod

Hi,

In Word:
.. Insert a «Spouse_Y_N» mergefield followed by a «Spouse_Name» mergefield ;
.. select both mergefields and press Ctrl-F9 to enclose them in a new field, thus {«Spouse_Y_N»«Spouse_Name»};
.. fill in around the new field braces thus, paying careful attention to the spacing {IF{«Spouse_Y_N»= "Yes" «Spouse_Name»};
.. position the cursor anywhere in this field and press F9 to update it;
.. run your mailmerge.

If your «Spouse_Y_N» mergefield can contain 'Yes', 'yes', 'Y' or 'y' for a 'Yes response, you'll need to do a bit more work. In this
case, when you forst insert the «Spouse_Y_N» mergefield:
.. select it and press Shift-F9. You should see {MERGEFIELD Spouse_Y_N}
.. add an uppercase switch to it, thus: {MERGEFIELD Spouse_Y_N \* Upper}
.. press F9 to update the field
.. continue as before, except that you code the overall field as {IF{«Spouse_Y_N»= "Y*" «Spouse_Name»}
 
V

Veteran of the software cycles

macropod,
Here's what I did: inserted two merge fields, selected them, pressed
Ctrl-F9, typed "IF{" INSIDE the first bracket, typed ="Yes" between 2 merge
fields.

When I press F9 to update the coding, it immediately runs that sequence,
inserting spouse's name ("Anna Bannana"), rather than leaving the coding.

In my dropdown Insert Word Field list, I don't have an "{IF" code. When I
typed "{IF" outside the first brace, it does not become part of the totalcode
when I press F9, which is why I typed "IF{ inside the first brace.

Many thanks for your help so far.


macropod said:
Hi,

In Word:
.. Insert a «Spouse_Y_N» mergefield followed by a «Spouse_Name» mergefield ;
.. select both mergefields and press Ctrl-F9 to enclose them in a new field, thus {«Spouse_Y_N»«Spouse_Name»};
.. fill in around the new field braces thus, paying careful attention to the spacing {IF{«Spouse_Y_N»= "Yes" «Spouse_Name»};
.. position the cursor anywhere in this field and press F9 to update it;
.. run your mailmerge.

If your «Spouse_Y_N» mergefield can contain 'Yes', 'yes', 'Y' or 'y' for a 'Yes response, you'll need to do a bit more work. In this
case, when you forst insert the «Spouse_Y_N» mergefield:
.. select it and press Shift-F9. You should see {MERGEFIELD Spouse_Y_N}
.. add an uppercase switch to it, thus: {MERGEFIELD Spouse_Y_N \* Upper}
.. press F9 to update the field
.. continue as before, except that you code the overall field as {IF{«Spouse_Y_N»= "Y*" «Spouse_Name»}

--
Cheers
macropod
[MVP - Microsoft Word]


Veteran of the software cycles said:
I'm using Word 2003 with an Excel spreadsheet as my data source to create a
merge in a lengthy document. I need an If...Then-type field that will allow
me to have another field code in the Insert This Text area.

Example:

If: "Spouse_Y_N" Is Equal to: "Yes", then insert: [Spouse Name].

Where Spouse Name is also a field pulling from the same Excel spreadsheet.

Any ideas on how I can achieve this?

Thanks in advance.
 
D

Doug Robbins - Word MVP on news.microsoft.com

If you use Alt+F9 to toggle on the display of the field codes, the field
construction should look like

{ IF { MERGEFIELD Spouse_Y_N } = "Yes" { MERGEFIELD "Spouse Name" } }

where each pair of field delimiters { } was either converted from the
<<mergefieldname>> or by using Ctrl+F9

Use Alt+F9 to toggle off the display of the field codes. Pressing F9 to
update the field, may cause it to display the result for the current record
in the data source. If you execute the merge however, you should get the
appropriate result for each record.

--
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, originally posted via msnews.microsoft.com

"Veteran of the software cycles"
macropod,
Here's what I did: inserted two merge fields, selected them, pressed
Ctrl-F9, typed "IF{" INSIDE the first bracket, typed ="Yes" between 2
merge
fields.

When I press F9 to update the coding, it immediately runs that sequence,
inserting spouse's name ("Anna Bannana"), rather than leaving the coding.

In my dropdown Insert Word Field list, I don't have an "{IF" code. When I
typed "{IF" outside the first brace, it does not become part of the
totalcode
when I press F9, which is why I typed "IF{ inside the first brace.

Many thanks for your help so far.


macropod said:
Hi,

In Word:
.. Insert a «Spouse_Y_N» mergefield followed by a «Spouse_Name»
mergefield ;
.. select both mergefields and press Ctrl-F9 to enclose them in a new
field, thus {«Spouse_Y_N»«Spouse_Name»};
.. fill in around the new field braces thus, paying careful attention to
the spacing {IF{«Spouse_Y_N»= "Yes" «Spouse_Name»};
.. position the cursor anywhere in this field and press F9 to update it;
.. run your mailmerge.

If your «Spouse_Y_N» mergefield can contain 'Yes', 'yes', 'Y' or 'y' for
a 'Yes response, you'll need to do a bit more work. In this
case, when you forst insert the «Spouse_Y_N» mergefield:
.. select it and press Shift-F9. You should see {MERGEFIELD Spouse_Y_N}
.. add an uppercase switch to it, thus: {MERGEFIELD Spouse_Y_N \* Upper}
.. press F9 to update the field
.. continue as before, except that you code the overall field as
{IF{«Spouse_Y_N»= "Y*" «Spouse_Name»}

--
Cheers
macropod
[MVP - Microsoft Word]


"Veteran of the software cycles"
I'm using Word 2003 with an Excel spreadsheet as my data source to
create a
merge in a lengthy document. I need an If...Then-type field that will
allow
me to have another field code in the Insert This Text area.

Example:

If: "Spouse_Y_N" Is Equal to: "Yes", then insert: [Spouse Name].

Where Spouse Name is also a field pulling from the same Excel
spreadsheet.

Any ideas on how I can achieve this?

Thanks in advance.
 
V

Veteran of the software cycles

Hi, guys, I got it to work. Many thanks.



Doug Robbins - Word MVP on news.microsof said:
If you use Alt+F9 to toggle on the display of the field codes, the field
construction should look like

{ IF { MERGEFIELD Spouse_Y_N } = "Yes" { MERGEFIELD "Spouse Name" } }

where each pair of field delimiters { } was either converted from the
<<mergefieldname>> or by using Ctrl+F9

Use Alt+F9 to toggle off the display of the field codes. Pressing F9 to
update the field, may cause it to display the result for the current record
in the data source. If you execute the merge however, you should get the
appropriate result for each record.

--
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, originally posted via msnews.microsoft.com

"Veteran of the software cycles"
macropod,
Here's what I did: inserted two merge fields, selected them, pressed
Ctrl-F9, typed "IF{" INSIDE the first bracket, typed ="Yes" between 2
merge
fields.

When I press F9 to update the coding, it immediately runs that sequence,
inserting spouse's name ("Anna Bannana"), rather than leaving the coding.

In my dropdown Insert Word Field list, I don't have an "{IF" code. When I
typed "{IF" outside the first brace, it does not become part of the
totalcode
when I press F9, which is why I typed "IF{ inside the first brace.

Many thanks for your help so far.


macropod said:
Hi,

In Word:
.. Insert a «Spouse_Y_N» mergefield followed by a «Spouse_Name»
mergefield ;
.. select both mergefields and press Ctrl-F9 to enclose them in a new
field, thus {«Spouse_Y_N»«Spouse_Name»};
.. fill in around the new field braces thus, paying careful attention to
the spacing {IF{«Spouse_Y_N»= "Yes" «Spouse_Name»};
.. position the cursor anywhere in this field and press F9 to update it;
.. run your mailmerge.

If your «Spouse_Y_N» mergefield can contain 'Yes', 'yes', 'Y' or 'y' for
a 'Yes response, you'll need to do a bit more work. In this
case, when you forst insert the «Spouse_Y_N» mergefield:
.. select it and press Shift-F9. You should see {MERGEFIELD Spouse_Y_N}
.. add an uppercase switch to it, thus: {MERGEFIELD Spouse_Y_N \* Upper}
.. press F9 to update the field
.. continue as before, except that you code the overall field as
{IF{«Spouse_Y_N»= "Y*" «Spouse_Name»}

--
Cheers
macropod
[MVP - Microsoft Word]


"Veteran of the software cycles"
I'm using Word 2003 with an Excel spreadsheet as my data source to
create a
merge in a lengthy document. I need an If...Then-type field that will
allow
me to have another field code in the Insert This Text area.

Example:

If: "Spouse_Y_N" Is Equal to: "Yes", then insert: [Spouse Name].

Where Spouse Name is also a field pulling from the same Excel
spreadsheet.

Any ideas on how I can achieve this?

Thanks in advance.
 

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