How to Fix Word VBA Combo Box Year Value Returning Blank
Question details
The user needs to resolve an issue where a VBA user form correctly inserts month and day values into a document but returns a blank value for the year combo box.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Using a Word VBA user form to collect date components (month, day, year) via combo boxes and transfer them into the document.
- Observed behavior
- The month and day values are inserted correctly, but the year value from its respective combo box appears blank in the document.
Ensure you have the Developer tab enabled to access your VBA Editor, and confirm that the Year combo box in your UserForm is properly populated with values during initialization.
Use DOCVARIABLE Fields in VBA to Transfer Values
Assign the combo-box values directly to Document Variables in your VBA code, which provides a reliable method for transferring data to specific fields in the document.
Instead of directly writing form values to document ranges or bookmarks, Document Variables store the data in the document's background. You can then use field codes to display this data anywhere in the text.
In your document, press Ctrl+F9 to insert empty field braces. Type DOCVARIABLE inside them, for example: { DOCVARIABLE Month }, { DOCVARIABLE Day }, and { DOCVARIABLE Year }.
In your UserForm's code, assign the combo-box values to the variables using: ActiveDocument.Variables("Year") = ComboBoxYear.Value.
After assigning the values, force the document to refresh its fields by adding this line to your code: ActiveDocument.Range.Fields.Update.
Return to your document and press Alt+F9 to toggle between showing the field codes and displaying their actual updated results.

Target Header and Footer Story Ranges for Updates
If your DOCVARIABLE fields are located in the document's headers or footers, standard field updates will bypass them. You must target these ranges specifically in your VBA code.
Manage VBA Macros and Forms Easily in WPS Office
WPS Office Writer offers extensive support for VBA macros and user forms, allowing you to create, edit, and troubleshoot scripts like combo box date selectors without compatibility issues.
- 1. Open your Document: Launch WPS Writer and open your macro-enabled document.
- 2. Access the VBA Editor: Navigate to the Developer tab and click on 'Visual Basic' to open the built-in VBA editor.
- 3. Edit UserForm Code: Modify your user form code to assign combo box values to DOCVARIABLEs and test the execution seamlessly.

Frequently Asked Questions
Why is my VBA combo box returning a blank value to the document?
A blank value typically occurs if the combo box hasn't been properly populated during the UserForm_Initialize event, or if the code unloads the form (using 'Unload Me') before the selected value can be read and assigned to a document variable.
What is the keyboard shortcut to insert a DOCVARIABLE field?
You can insert a field code by pressing Ctrl+F9 in your document. This creates curly braces {} where you can type 'DOCVARIABLE' followed by your variable name, such as '{ DOCVARIABLE Year }'.
How do I view or hide field codes like DOCVARIABLE in my document?
Press Alt+F9 on your keyboard. This shortcut toggles the document view between displaying the underlying field codes (e.g., { DOCVARIABLE Year }) and showing their actual evaluated results.
Why aren't my DOCVARIABLE fields updating in the header?
The standard ActiveDocument.Range.Fields.Update command only affects the main body of the text. To update fields placed in a header or footer, you must write VBA code that specifically targets those header/footer story ranges or loops through your document's sections.




