Autopopulating a form field from a drop down form field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created a form in Word. One of the fields is a drop-down box (yes/no). Based on what they select in this drop down box, I would like another field (regular text field) to automatically populate with pre-defined text. Does anyone know how to do this?

:) Shannon
 
Hi Shannon

This is a two-step process.

Step 1: Create a macro like the following:

Sub UpdateTextFormField()

With ActiveDocument

If .FormFields("DropDown1").Result = "Yes" Then
.FormFields("Text1").Result = "You chose yes"

ElseIf .FormFields("DropDown1").Result = "No" Then
.FormFields("Text1").Result = "You chose no"

End If

End With

End Sub

If you're not sure what to do with that macro, see
http://www.gmayor.com/installing_macro.htm

You will need to edit that macro in three ways:
(a) Change the name of the drop down field to match the name of your drop
down field
(b) Change the name of the text field to match the name of your text field
(c) Change the text you want to display in the text field.

Note that it's a good idea to give your fields meaningful names. You can
change the name by turning off protection, then right-clicking the field.
Names like txtCompanyName are more useful than "Text1".

I would also change the name of the macro (ie the word after Sub). Call it
something more specific like UpdateEmployeeStatus or UpdateCustomerName.

Step 2: Tell the drop down field to run the macro when the user exits the
drop down field. To do that, turn off protection on the form. Right-click
the field and choose Properties. In the Exit box, select your macro.

Turn protection on, and test it out.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


Shannon said:
I have created a form in Word. One of the fields is a drop-down box
(yes/no). Based on what they select in this drop down box, I would like
another field (regular text field) to automatically populate with
pre-defined text. Does anyone know how to do this?
 
Hi Shannon,

For purposes of illustration, I'll assume the dropdown form field has
the default name Dropdown1 and that you put in the items Yes and No.
You should also check the 'Calculation on exit' box in the Properties
dialog.

In the other place, do not put a text form field. Instead, put in this
field, using Ctrl+F9 to insert each matching pair of field braces:

{ IF {Dropdown1} = "Yes" "text for yes" "text for no" }

The Yes in this field must match the Yes item in the dropdown,
including capitalization. Replace the two text items with whatever
text you need for your form. Press F9 to collapse the field code, and
protect the form. When the user changes the dropdown and tabs to
another form field, the IF field will automatically update to the
corresponding text.
 
Hi Shannon

Jay Freedman's solution is both simpler and better than the one I proposed.
Use Jay's proposal!

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


Jay Freedman said:
Hi Shannon,

For purposes of illustration, I'll assume the dropdown form field has
the default name Dropdown1 and that you put in the items Yes and No.
You should also check the 'Calculation on exit' box in the Properties
dialog.

In the other place, do not put a text form field. Instead, put in this
field, using Ctrl+F9 to insert each matching pair of field braces:

{ IF {Dropdown1} = "Yes" "text for yes" "text for no" }

The Yes in this field must match the Yes item in the dropdown,
including capitalization. Replace the two text items with whatever
text you need for your form. Press F9 to collapse the field code, and
protect the form. When the user changes the dropdown and tabs to
another form field, the IF field will automatically update to the
corresponding text.
(yes/no). Based on what they select in this drop down box, I would like
another field (regular text field) to automatically populate with
pre-defined text. Does anyone know how to do this?
 
Insert field using the drop down field from the Forms
toolbar then double click on the field to get the dialog
box that will allow you to enter your list of options.
It is limited in 2002 to 25 entries.
-----Original Message-----
I have created a form in Word. One of the fields is a
drop-down box (yes/no). Based on what they select in
this drop down box, I would like another field (regular
text field) to automatically populate with pre-defined
text. Does anyone know how to do this?
 
Sorry I did not see your entire question and I do not
know the answer.
-----Original Message-----
I have created a form in Word. One of the fields is a
drop-down box (yes/no). Based on what they select in
this drop down box, I would like another field (regular
text field) to automatically populate with pre-defined
text. Does anyone know how to do this?
 
I have tried this with Word2000 and am having no luck.
I have 3 items in dropox and have done this
{IF {Dropdown1} = " " " " {IF {Dropdown1} = "Steve" "call" {IF {Dropdown1} =
"Mitch" "fax" }}}

When I select 'our' or 'Steve' from the dropbox, I am getting nothing

What am I missing?
 
For three entries
Mitch
Steve
and a single space -
{ IF{ Dropdown1 } <> " " "{ IF { Dropdown1 } = "Steve" "Call" "{ If{
Dropdown1 } = "Mitch" "Fax" " " }" }" " " }
will work, provided you have calculate on exit flagged on the dropdown1
field and you tab out of it.

Alternatively you could use a selection of fields on the same line to cover
every eventuality.
{ If{ Dropdown1 } = "Mitch" "Fax"}{ If{ Dropdown1 } = "Steve" "Call" }{
If{ Dropdown1 } = " " " " }

You made no mention of 'our' and that appears irrelevant from the field
information you have provided.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Good Morning,
I've done this but, still no luck.
I Ctrl+F9 after my drop down and insert the code listed and then F9. I lock
the template and then save it. When I create new doc and select either name,
I get nothing.

I've used macros on exit to poulate a text but, this looked simpler.
What am I missing?

Bryan
 
You can't do this with only one Ctrl+F9. Each pair of matching braces must
be inserted with Ctrl+F9 -- you should be creating fields within fields, but
simply pasting in the text from the post gives you just text, not fields.

You could paste in the text from the post, then select the text between one
pair of matching braces -- for example, Dropdown1 -- and press Ctrl+F9 to
make that field; then delete the plain-text braces and leave only the field
delimiters. Repeat that for each of the other pairs.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
I got it!
I did not Ctrl+F9 to create the brackets around Dropdown1, I keyed those in.

Thanks for clearing that up!

Bryan
 
Quick question.
Once this is created and I want to change it down the road, how does one
know that this is in the form?

How would you be able to find to change?

Thanks,
Bryan
 
One way is to press Alt+F9, which toggles between field results and field
codes (that is, press it again to switch back). When you can see the codes
in the document, you can use the Find dialog to look for specific text in
the field code. By the way, the search code ^19 will locate the left "brace"
field delimiter, so you could look for the expression
^19 IF
to find all the IF fields.

Another way is to press F11 to jump to the next field of any kind. If you
don't have a lot of other kinds of fields, such as REF fields, this might be
quicker.
 

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

Back
Top