How to Configure Word Mail Merge Recipient Filter With AND/OR Logic
🔍 WiseChecker

How to Configure Word Mail Merge Recipient Filter With AND/OR Logic

When you run a mail merge in Word, you often need to send letters or emails only to a subset of your data source. The standard filter dialog in Word lets you select recipients based on field values, but it uses AND logic by default. This means all conditions must be true at the same time, which can exclude records you want to include. This article explains how to set up a mail merge recipient filter that uses AND logic and how to work around Word’s limited OR logic support using advanced query options.

Key Takeaways: Filtering Mail Merge Recipients With AND/OR Logic

  • Mail Merge Recipient dialog > Filter link: Opens the Filter and Sort dialog where you can define up to six AND conditions by default.
  • Field > Comparison > Compare to columns: Each row becomes an AND condition; all must be true for a record to be included.
  • SQL query via the .mdb or .odc connection: The only reliable method to implement OR logic, by editing the data source connection file outside Word.

ADVERTISEMENT

How Word Mail Merge Filtering Works

Word’s mail merge feature connects to a data source such as an Excel worksheet, Access database, Outlook contacts, or a comma-separated values file. When you choose to filter recipients, Word displays a dialog that lets you specify conditions on one or more fields.

The filter dialog in Word uses a row-based interface. Each row represents one condition. When you add multiple rows, Word treats them as AND conditions by default. For example, if you set City equals “New York” and Status equals “Active”, only records where both conditions are true will be included. This is AND logic.

Word does not provide a built-in option to switch from AND to OR logic in the standard filter dialog. If you need OR logic, such as including recipients from either “New York” or “Chicago”, you must use a workaround. The most reliable method involves editing the data source connection file to insert a custom SQL WHERE clause that combines conditions with OR.

Prerequisites for Filtering

Before you start, ensure your data source is ready. The data source must have field names in the first row. For Excel, the first row must contain column headers. For Access, the table or query must have defined field names. Word uses these field names in the filter dialog.

You also need to know the exact values you want to filter on. Typos in the filter dialog cause no records to match. Test your filter with a small data set first.

Steps to Apply an AND Filter in the Mail Merge Recipient Dialog

The standard filter dialog in Word supports AND logic. Follow these steps to set up an AND filter.

  1. Open the Mail Merge Recipients dialog
    In Word, go to Mailings > Select Recipients and choose your data source. Then click Mailings > Edit Recipient List. The Mail Merge Recipients dialog opens, showing all records from your data source.
  2. Open the Filter and Sort dialog
    In the Mail Merge Recipients dialog, click the Filter link located at the top right. The Filter and Sort dialog appears with the Filter Records tab selected.
  3. Define your first condition
    In the Field drop-down list, select the field you want to filter on. In the Comparison drop-down list, select an operator such as Equal to, Not equal to, Greater than, Less than, or Contains. In the Compare to text box, type the value. For example, select City, Equal to, and type New York.
  4. Add additional AND conditions
    Click the next empty row. Select a different field, comparison, and value. Each new row adds an AND condition. For example, add Status, Equal to, Active. Now only records where City is New York AND Status is Active will be included.
  5. Apply the filter
    Click OK to close the Filter and Sort dialog. Back in the Mail Merge Recipients dialog, only the filtered records are checked. Click OK to return to the document. Word will merge only those recipients that meet all your conditions.

ADVERTISEMENT

How to Create an OR Filter Using a Custom SQL Query

Because Word’s filter dialog only supports AND logic, you must edit the data source connection to use OR logic. This method works when your data source is an Excel file or an Access database. You will modify the connection file that Word uses to link to the data.

  1. Create the mail merge with your data source
    In Word, go to Mailings > Select Recipients and choose your data source. Complete the mail merge setup as usual but do not apply any filter yet.
  2. Save the mail merge main document
    Save your Word document with a name you can find later. The connection information is stored in the document.
  3. Locate the connection file
    Close Word. Open File Explorer and navigate to the folder where your data source file is located. Look for a file with the extension .odc or .mdb. For Excel connections, Word often creates an Office Data Connection (.odc) file. For Access connections, the .mdb file is your data source itself. If you do not see an .odc file, open your Word document again and check the connection type.
  4. Open the .odc file in Notepad
    Right-click the .odc file and choose Open with > Notepad. You will see XML content. Look for a line that contains the element. This element holds the SQL query that Word runs against the data source.
  5. Edit the SQL query to include OR logic
    Replace the existing query with a custom query that uses OR. For example, if your original query is SELECT FROM Sheet1$, change it to SELECT FROM Sheet1$ WHERE City = 'New York' OR City = 'Chicago'. Save the .odc file.
  6. Reopen the Word document and refresh the connection
    Open your saved Word document. Word may prompt you to confirm that you want to refresh the connection. Click Yes. Go to Mailings > Edit Recipient List. The list should show only the records that match your OR condition. Complete the merge as usual.

Important Notes About the SQL Query Method

The SQL query method works best with Excel and Access data sources. For other data sources like Outlook contacts or text files, this method may not work because Word does not create an editable .odc file. Also, you must know basic SQL syntax. Incorrect syntax will cause Word to show an error when you refresh the connection.

If you need to combine AND and OR logic, use parentheses in the SQL query. For example: SELECT FROM Sheet1$ WHERE (City = 'New York' OR City = 'Chicago') AND Status = 'Active'. This query returns records that are in either city AND have an active status.

Common Issues When Filtering Mail Merge Recipients

Word Shows No Records After Applying the Filter

When you apply a filter and the recipient list becomes empty, the most likely cause is a mismatch in field names or values. Check that the field name in the filter dialog exactly matches the column header in your data source. Also verify that the value you typed exists in the data source. For text fields, Word is case-insensitive but space-sensitive. A trailing space in the value will cause no matches.

OR Logic Does Not Work in the Standard Filter Dialog

Some users try to create OR logic by adding multiple rows and expecting Word to treat them as OR conditions. Word does not support this. Each row is always an AND condition. The only way to get OR logic is to edit the SQL query as described above. Alternatively, you can create a new field in your data source that combines the OR logic into a single value, then filter on that field.

Changes to the Data Source Are Not Reflected in Word

If you update the data source after setting up the filter, Word may still show old data. To refresh, click Mailings > Edit Recipient List. In the dialog, click the data source name, then click Refresh. Word will reload the data and reapply the filter.

Mail Merge Recipient Filter: Standard Dialog vs SQL Query Method

Item Standard Filter Dialog SQL Query via .odc File
Logic supported AND only AND, OR, and combined
Ease of use Point and click, no coding Requires editing XML and writing SQL
Data source types All supported data sources Excel and Access only
Risk of errors Low Medium if SQL syntax is wrong
Real-time updates Yes, after refresh Yes, after closing and reopening the document

Use the standard dialog for simple AND filters. Use the SQL method only when you need OR logic and your data source is Excel or Access.

The mail merge recipient filter in Word handles AND logic directly through the Filter and Sort dialog. For OR logic, you must edit the data source connection file to insert a custom SQL WHERE clause. This workaround gives you full control over complex filtering conditions. After setting up your filter, always preview the merged document by clicking Mailings > Preview Results to verify the correct recipients appear. As an advanced tip, you can combine multiple OR conditions in one SQL query using parentheses and the OR keyword, which is not possible through the standard dialog.

ADVERTISEMENT