Document Editing Problems

How to Use AND and OR Conditions in Microsoft Word IF Fields

Adam DavisAdam Davis Nov 3, 2026 869 views

Question details

The user needs to implement multiple conditions (AND/OR logic) using IF and COMPARE fields in Microsoft Word mail merge and resolve syntax errors.

How to Use AND and OR Conditions in Microsoft Word IF Fields
Product
Microsoft Word
Device & OS
not provided
Scenario
Creating advanced mail merge documents with conditional text that relies on evaluating multiple data fields simultaneously.
Observed behavior
Users encounter an 'Unknown op code for conditional' error when using COMPARE and IF fields, preventing the mail merge logic from executing correctly.
Before you start

Ensure your data source is successfully linked to your Word document and that you use the keyboard shortcut (Ctrl+F9) to insert field code braces, rather than typing them manually.

Solution 1Recommended

Use the COMPARE Field with Correct Spacing

Resolve the 'Unknown op code for conditional' error by adding proper spaces inside your field code syntax.

The COMPARE field evaluates multiple possibilities and returns a true or false result. However, Microsoft Word requires strict spacing around operators. If you miss a space, Word cannot parse the formula and throws an error.

1
Insert field braces

Press Ctrl+F9 on your keyboard to insert the special curly braces for your IF and COMPARE fields.

2
Enter the formula

Type your logical condition inside the braces. Ensure there is a space before and after every equals sign. For example: { IF { COMPARE { MERGEFIELD CY_TYP } = "2" } = 1 "Granted" "Not granted" }.

3
Verify specific spacing

Double-check that there is an exact space directly between the final equals sign (=) and the number 1. This missing space is the primary cause of the 'Unknown op code' error.

4
Toggle and test

Press Alt+F9 to toggle the field codes off and view the result, then run your mail merge preview to confirm the condition works.

Use the COMPARE Field with Correct Spacing
Formatting Tip: Always keep field codes visible (Alt+F9) while editing so you can accurately count the spaces between your nested formulas.
Free Microsoft Office alternative

Perform Seamless Mail Merges with WPS Office

If you are frustrated by complicated field code errors in Microsoft Word, consider switching to WPS Office. It provides an intuitive mail merge interface, handles conditional formatting smoothly, and remains a lightweight, highly compatible alternative.

Free and lightweight alternative to Microsoft OfficeFully compatible with Microsoft Word .docx formats and mail merge featuresIntuitive user interface for inserting merge fields without complex codingCross-platform support for Windows, Mac, and Linux
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get the 'Unknown op code for conditional' error in Word?

This error is typically caused by missing spaces in your IF or COMPARE field formulas. Word requires a space on both sides of mathematical operators, such as the equals sign (=), to properly read the condition.

How do I correctly type the curly brackets for field codes?

You cannot type the curly braces { } manually using the standard bracket keys on your keyboard. You must press Ctrl+F9 on Windows (or Cmd+F9 on Mac) to insert valid, functional field code brackets.

Can I use the words 'AND' or 'OR' directly in a Word IF field?

No, Microsoft Word field codes do not support direct 'AND' or 'OR' text operators in standard IF fields. Instead, you must use nested IF fields or the COMPARE field to evaluate multiple conditions simultaneously.