# [SOLVED] MS Word Macro. Form Field Reference Question



## gunerstahl (Sep 7, 2011)

Hi all, 

I have a question regarding a macro that I am trying to write for a word document that I have.

I have a dropdown menu in the document that is bookmarked as "DropDown1". I also have a formfield that is bookmarked as "Text1". I want to make it so that depending on the choice the user makes in the dropdown menu, the text box is filled in with predetermined text.

I am not too familiar with VBA programing, so I may have made some obvious mistakes in the code (which I based on an example I found online). Here is what I have so far:


```
Sub Dropdown()
Dim FF As Formfields
Set FF = ActiveDocument.FormFields("Text1")
Select Case ActiveDocument.FormFields("Dropdown1").Result
    Case "Construction"
        ActiveDocument.FormFields("Text1").Result = "Construction"
    Case "Design"
        ActiveDocument.FormFields("Text1").Result = "Design"
    Case "Planning"
        ActiveDocument.FormFields("Text1").Result = "N/A"
End Select
End Sub
```
When I run the macro, it says "type mismatch" on line 3.

Any help would be appreciated.

Thanks


----------



## macropod (Apr 11, 2008)

*Re: MS Word Macro. Form Field Reference Question*

Hi Gunerstahl,

Unless you want the text formfield to be editable, you can achieve what you're after without a macro, using ordinary fields (not formfields), coded as:
{IF{REF Dropdown1}= "Planning" "N/A" {REF Dropdown1}}

Simply check the dropdown formfield's 'calculate on exit' property.

*Note*: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message.


----------



## gunerstahl (Sep 7, 2011)

*Re: MS Word Macro. Form Field Reference Question*

Wow, thanks. 

I actually was able to also find a way this afternoon using a macro, but the way that you suggested is less in depth (I mean that as a good thing, it doesn't make the problem any more complicated than it needs to be). 

I'll post the code I used just as an FYI.


```
Sub Sample()
Select Case ActiveDocument.FormFields("Dropdown1").Result 
Case "Construction"
ActiveDocument.FormFields("Text1").Result = "Type this when Construction is chosen"
Case "Design"
ActiveDocument.FormFields("Text1").Result = "Type this when Design is chosen"
Case "Planning"
ActiveDocument.FormFields("Text1").Result = "Type this when Planning is Chosen"
End Select
End Sub
```
I think I will use the way you suggested (some of the users of this form may not like the idea of a macro being in it).


----------

