Hi,
I'm trying to figure out a way to add (From the legacy tools) to a word document both a Dropdown & and a Text Form Field.
The Dropdown tool will have different selections, and based on the selection, the Text Form Field will display a different text content.
Is there a way to code this in VB?
Greatly appreciate it in advance.
Raudel
Update Content of TextFormField based on Dropdown Selection
-
- 2StarLounger
- Posts: 136
- Joined: 17 Apr 2017, 19:16
-
- Administrator
- Posts: 78930
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Update Content of TextFormField based on Dropdown Select
Create a macro like this, using the appropriate names and values of course:
While the document is unprotected, double-click the dropdown.
Select the macro you created to run on Exit:
Code: Select all
Sub UpdateText()
Select Case ActiveDocument.FormFields("Dropdown1").Result
Case "a"
ActiveDocument.FormFields("Text1").Result = "this"
Case "b"
ActiveDocument.FormFields("Text1").Result = "that"
Case "c"
ActiveDocument.FormFields("Text1").Result = "other"
End Select
End Sub
Select the macro you created to run on Exit:
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78930
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Update Content of TextFormField based on Dropdown Select
Create a macro like this, using the appropriate names and values of course:
While the document is unprotected, double-click the dropdown.
Select the macro you created to run on Exit:
Code: Select all
Sub UpdateText()
Select Case ActiveDocument.FormFields("Dropdown1").Result
Case "a"
ActiveDocument.FormFields("Text1").Result = "this"
Case "b"
ActiveDocument.FormFields("Text1").Result = "that"
Case "c"
ActiveDocument.FormFields("Text1").Result = "other"
End Select
End Sub
Select the macro you created to run on Exit:
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Update Content of TextFormField based on Dropdown Select
Unless you plan to edit the text formfield, you don't need one - simply use a series of IF fields that reference the dropdown formfield's internal bookmark and check the formfield's 'calculate on exit' property. For example:
{IF{REF Dropdown1}= "Item 1" "Item 1 output text"}{IF{REF Dropdown1}= "Item 2" "Item 2 output text"}{IF{REF Dropdown1}= "Item 3" "Item 3 output text"}
where 'Dropdown1' is the dropdown formfield's internal bookmark name.
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required.
{IF{REF Dropdown1}= "Item 1" "Item 1 output text"}{IF{REF Dropdown1}= "Item 2" "Item 2 output text"}{IF{REF Dropdown1}= "Item 3" "Item 3 output text"}
where 'Dropdown1' is the dropdown formfield's internal bookmark name.
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required.
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- 2StarLounger
- Posts: 136
- Joined: 17 Apr 2017, 19:16
Re: Update Content of TextFormField based on Dropdown Select
Thank you, HansV and Macropod, both for your replies,
In the template I'm creating I do need the user to be able to modify the TextFormField if desired even after the drop down has been selected. But on a typical day the standard would be to leave the fields as updated by the macro ran on exit.
The code worked like a charm.
Thank you very much for always being so very helpful.
RaudelJr
In the template I'm creating I do need the user to be able to modify the TextFormField if desired even after the drop down has been selected. But on a typical day the standard would be to leave the fields as updated by the macro ran on exit.
The code worked like a charm.
Thank you very much for always being so very helpful.
RaudelJr