How to Use AND and OR Conditions in Microsoft Word IF Fields
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.

- 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.
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.
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.
Press Ctrl+F9 on your keyboard to insert the special curly braces for your IF and COMPARE fields.
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" }.
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.
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 Nested IF Fields for Complex Conditions
Nest multiple IF statements together as an alternative to COMPARE when building complex AND/OR logic.
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.

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.




