logo
search
Document Editing Problems

How to Use a SET Field Code Inside an IF Field Code in Word

Maira MehtabMaira Mehtab Sep 22, 2026 868 views

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.
Before you start

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.

Solution 1Recommended

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.

1
Insert Field Braces

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.

2
Construct the Nested Code

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" } }.

3
Adjust Condition and Values

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.

4
Update the Fields

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.

Field Code Syntax Strictness: Make sure you use Ctrl+F9 for every set of inner and outer braces in your nested field. Missing a brace or typing it manually will cause the formula to fail.
Advanced Document Editing in WPS

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. 1. Open your document: Launch WPS Office Writer and open your DOCX template or file.
  2. 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. 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.
Fully compatible with Microsoft Word DOCX and DOC formats.Supports advanced field codes and legacy form controls.Lightweight installation with a clean, user-friendly interface.Cross-platform support for Windows, Mac, Linux, iOS, and Android.
microsoft office alternative - wps office

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.