How to Use a SET Field Code Inside an IF Field Code in Word
Question details
The user needs to assign a bookmark value conditionally based on the selection stored in another bookmark using legacy form controls, without relying on macros or plugins.
- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating a dynamic document template with conditional text or form fields based on user selection.
- Observed behavior
- The user wants to set up a nested field structure where an IF field evaluates a condition to determine the value assigned to a bookmark via a SET field.
Ensure your document has the necessary legacy form controls or source bookmarks already created. Remember that all field code braces must be inserted using the designated keyboard shortcut rather than typing standard curly brackets.
Use Nested Field Structure with the Field Command
Nest an IF field inside a SET field to evaluate a condition and automatically assign the resulting value to a new bookmark.
By nesting field codes, Word allows you to run logical tests and store the results in bookmarks dynamically. This is particularly useful for building smart templates that adapt to dropdown selections.
Press Ctrl+F9 on your keyboard to insert the special field code braces { }. Do not type the standard curly brackets from your keyboard, as Word will treat them as plain text.
Inside the main braces, type your SET command, then press Ctrl+F9 again to insert the nested IF statement. It should look like this: { SET bookmark2 { IF { REF dd1 } = "option1" "value2" "value1" } }.
Replace 'dd1' with the name of your source bookmark or dropdown. Replace 'option1' with the condition you want to check, and 'value2' / 'value1' with the specific text values you want to assign based on the true/false outcome.
After modifying the dropdown value or source bookmark, highlight the document text (Ctrl+A) and press F9 to update the fields and apply the conditional logic.
Handle Complex Field Codes Easily with WPS Writer
WPS Office Writer fully supports Microsoft Word field codes, including nested IF and SET fields. You can seamlessly create and manage advanced, dynamic templates with legacy form controls.
- 1. Open your document: Launch WPS Office Writer and open your DOCX template or file.
- 2. Insert field codes: Press Ctrl+F9 to create the field brackets { } and type your SET and IF logic exactly as you would in Microsoft Word.
- 3. Update and test: Right-click the nested field code and select 'Update Field', or simply select it and press F9 to test your conditional logic.

Frequently Asked Questions
Why is my nested field code displaying as plain text instead of executing?
This usually happens if you type the curly braces manually using the keyboard. You must insert field code braces by pressing Ctrl+F9 (or Cmd+F9 on Mac) for Word to recognize them as functional fields.
How do I view or hide the field codes in my document?
You can toggle between viewing the underlying field codes and their generated results by pressing Alt+F9 on your keyboard. This allows you to easily edit complex nested logic.
Do nested field codes work without enabling macros?
Yes, field codes like IF, SET, and REF are native word processing functions. They do not require macros or VBA to operate, making your documents more secure and easier to share without triggering security warnings.




