Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ms Word 2000 Mail Merge Question 1

Status
Not open for further replies.

rebeccabarker

Programmer
Jun 24, 2004
14
US
I have a mail merge document that has a data source of an Access 2000 query. The query includes plan numbers and contract numbers. There can be multiple contract numbers per plan, so the data appears in the query like this:

Plan # Contract#
P5551 UG123456
P5551 GUF12345
P5552 UG234567
P5553 UG567890

I run the mail merge by selecting a specific record in the query and displaying the data for that record. Is there a way to run the mail merge for all records with a certain plan number? That way I will get one letter with multiple contract numbers on it instead of multiple letters, each with only one contract number.

I would really appreciate any help.

Thanks!
 
Hi rebeccabarker,

Maybe an IF THEN ELSE field in Word might help? This feature is available on the Mail Merge Toolbar (View/Toolbars?Mail Merge).

Here are some examples of what it can do:

Examples of IF fields
The IF field performs one of two alternative actions, depending on a condition you specify. For example, the statement "If the weather is sunny, we'll go to the park; if not, we'll go to the movies" specifies a condition that must be met (sunny weather) for a certain action to take place (going to the park). If the condition is not met, an alternative action occurs (going to the movies).

The following IF field is a similar type of statement. If the current data record contains "San Francisco" in the City field, Microsoft Word prints the first text in quotation marks in the merged document that results from that data record. Otherwise, Word prints the second set of text. This example uses the IF and MERGEFIELD fields together.

{ IF { MERGEFIELD City } = "San Francisco" "Please call our local office." "Please return the enclosed form in the provided envelope." }

Word inserts an IF field in this form when you click the Insert Word Field button on the Mail Merge toolbar and then click If...Then...Else.

Here are some examples of ways to modify the IF field codes by using them in concert with other field codes:

Compare a data field with another data field or bookmark

This IF field compares the number in the Rate data field with the number in the Discount data field. If the numbers are equal, the specified text is printed.

{ IF { MERGEFIELD Rate } = { MERGEFIELD Discount } "We will offer you a larger discount. " " " }

(If number in the Rate data field does not equal the number in the Discount field, no text is printed.)


Example 1
If the condition specified by this IF field is met, the INCLUDETEXT field inserts the contents of the indicated document. To specify the location and file name of the included document, use double backslash (\\) characters, as shown in the example. If the condition is not met, Word inserts the AutoText entry "Copyright."

{ IF { MERGEFIELD State } = "NY" "{ INCLUDETEXT c:\\worddocs\\contract.doc }" "{ AUTOTEXT Copyright }" }

Example 2
If the Company data field for a data record contains any information— that is, if the field is not blank— Word prints text from the CompanyAddress field. Otherwise, Word prints text from the HomeAddress field.

{ IF { MERGEFIELD Company } <> " " "{ MERGEFIELD CompanyAddress }" "{ MERGEFIELD HomeAddress }" }

Perform calculations in an IF field

In this example, the first = (Formula) field in the following example computes the current balance of each account. If a balance remains, the Formula field is repeated to report the current balance. If the computed balance is 0 (zero) or less, Word prints the alternative text, "Your account is paid in full. Thank you."

{ IF { = { MERGEFIELD Balance } - {MERGEFIELD Payment } } > 0 "Your current balance is { = { MERGEFIELD Balance } - { MERGEFIELD Payment } \# "$#,##0.00; " }." "Your account is paid in full. Thank you." }

Specify multiple conditions

You can specify multiple conditions by nesting a COMPARE field or another IF field inside an IF field.

Example 1
In this example, COMPARE fields examine the data fields CustomerNumber and CustomerRating as Word merges each data record. The AND function of the = (Formula) field returns a value of "1" (true) if both of the data field values indicate a satisfactory account, in which case Word prints the first text in quotation marks.

{ IF { = AND ( { COMPARE { MERGEFIELD CustomerNumber } >= 4 }, { COMPARE { MERGEFIELD CustomerRating } <= 3 } ) } = 1 "Satisfactory" "Unsatisfactory"}

Example 2
In this example, special rates are offered only to residents of California or Washington. If the State field specifies any other state, no additional text is printed because no alternative text has been specified in the second IF field.

{IF {MERGEFIELD State} = "CA" "For California residents, we offer special rates to Asia and Japan." "{IF {MERGEFIELD State} = "WA" "For Washington residents, we offer special rates to Asia and Japan." " "} "}

HTH,

Best,
Blue Horizon [2thumbsup]
 
Thanks for your quick reply.

I am familiar with if statements and use them on a daily basis in my job. My concern is that since I run the mail merge on a specific record, an if statement would not pick up other contract numbers that are associated with this plan because they are separate records in the query. I was wondering if there was a way to run the merge and say something like "select all the records from this query where plan number = P5551"? That way I would have one merged letter with all the data from any record that had the plan number I am looking for.

Any suggestions?
 
Thank you so much! Your last website had a link to something that looks like it will work for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top