Forms - linking drop down menus

S

Susan B. Quinn

I have a form template that has a drop down menu with six choices. I wanted
to via a macro to insert text at two bookmarks depending on which option they
choose from the menu.

At the moment it is dropping all the options in when I run the macro. How do
I link the two actions together so I only get the text I want.

This was the code I had so far:

Sub vcr_rank()
' Well Below Average option

ActiveDocument.Unprotect

If ActiveDocument.FormFields("VCR_ranking").Type = wdFieldFormDropDown Then
ActiveDocument.FormFields("VCR_ranking").DropDown.Value = 2
End If

With ActiveDocument
.Bookmarks("VCR_ability").Range.Text = "a weak"
.Bookmarks("VCR_decision").Range.Text = "need more time and assistance
when making"

End With

' Below Average option

If ActiveDocument.FormFields("VCR_ranking").Type = wdFieldFormDropDown Then
ActiveDocument.FormFields("VCR_ranking").DropDown.Value = 3
End If

With ActiveDocument
.Bookmarks("VCR_ability").Range.Text = "a limited"
.Bookmarks("VCR_decision").Range.Text = "need more time and assistance
when making"

End With

' Average option

If ActiveDocument.FormFields("VCR_ranking").Type = wdFieldFormDropDown Then
ActiveDocument.FormFields("VCR_ranking").DropDown.Value = 4
End If

With ActiveDocument
.Bookmarks("VCR_ability").Range.Text = "an average"
.Bookmarks("VCR_decision").Range.Text = "be able to"

End With

' Above Average option

If ActiveDocument.FormFields("VCR_ranking").Type = wdFieldFormDropDown Then
ActiveDocument.FormFields("VCR_ranking").DropDown.Value = 5
End If

With ActiveDocument
.Bookmarks("VCR_ability").Range.Text = "a strong"
.Bookmarks("VCR_decision").Range.Text = "have a strong ability to make"

End With

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True


End Sub
 
G

Greg

Susan,

You should probably use Case statement here instead of all the if
statements. Also because your user might change his/her mind, it is
probably best to redefine the bookmark range with each entry.

Try something like (you will need to define your own field and bookmark
names, values):
Sub OnExitDD()
Dim oBks As Bookmarks
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Set oBks = ActiveDocument.Bookmarks
Set oRng1 = oBks("Test1").Range
Set oRng2 = oBks("Test2").Range
ActiveDocument.Unprotect
Select Case ActiveDocument.FormFields("DropDown1").Result
Case Is = "A"
oRng1.Text = "Some A text here"
oRng2.Text = "Some other A text here"
oBks.Add "Test1", oRng1
oBks.Add "Test2", oRng2
Case Is = "B"
oRng1.Text = "Some B text here"
oRng2.Text = "Some other B text here"
oBks.Add "Test1", oRng1
oBks.Add "Test2", oRng2
'Case Is = C etc, etc,
End Select
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
End Sub
 
C

Charles Kenyon

You don't need a macro for this, merely an IF field conditioned on the
contents of a REF field which checks the contents of your dropdown. Make
sure that "calculate on exit" is checked in the properties for each of your
dropdown fields.

What you are talking about is what Word calls an "online form." For more
about online forms, follow the links at
http://addbalance.com/word/wordwebresources.htm#Forms or
http://word.mvps.org/FAQs/Customization/FillinTheBlanks.htm especially Dian
Chapman's series of articles.

Hope this helps,
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Charles Kenyon

Often so would I. On the other hand, getting macros to run on other people's
machines can be a headache.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top