1
votes

So I'm trying to create a conditional dropdown in Word. I've used a Legacy Drop-Down Form Field with multiple options.

What I want to happen is when one of the options is selected from the dropdown (and then I guess you have to Tab to enter it...), the Legacy Text Form Field below, that has a simple default text, should populate with a new string from the case statement.

Things that I've already done/got working:

  • the drop down is working, and on exit it runs a macro
  • case statement is written out
  • the result of the case statement is in a variable (string type), let's call it StringVar
  • can pull the text form field's text (default text) with ActiveDocument.FormFields("TextBox").Result

What I figure out, however, is how to replace the default text in the already existing Text Form Field with the case statement's string variable text.

I've tried ActiveDocument.FormFields("TextBox").Result = StringVar

but it doesn't change anything inside the text form field. The default text is still there.

1

1 Answers

1
votes

So I can answer my own question after pondering and being hit with an "oh, duh" moment.

I had unprotected the document (ActiveDocument.Unprotect Password:="") in order to do this:

ActiveDocument.Content.InsertAfter Text:=("This is my text")

because I was wondering if I was grabbing the right string.

Turns out,

ActiveDocument.FormFields("TextBox").Result = StringVar

DOES work. BUT the file has to be protected (filling in forms) for it to replace the string in the text form field. Otherwise, nothing shows up even though the result had indeed been updated. Fancy that.