Auto populate a field with a phone number

J

Johnny

I need a macro or method to auto populate a form filed with a telephone
number when I type in their name in another field on the same form.
 
J

Johnny

I've created a form that includs a drop down box with 5 people listed as the
chooses. There's another field on the form for a telephone number that has
to be manually typed in that corresponds to the peron that was selected in
the drop down box. Instead of having to manualy type in/change the phone
number each time a new person is selected, I would like to be able to
autopopulate the phone number. Hope that make more sense. Sorry!
 
G

Greg Maxey

You can set the value of the text field based on the dropdown entry
selected by running a macro on exit from the dropdown field. Here is
an example where the dropdown name is Dropdown1 and the text field name
is Text1.

Sub OnExitDD1()
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
Select Case oFld("Dropdown1").Result
Case Is = "Bob"
oFld("Text1").Result = "867-5309"
Case Is = "Joe"
oFld("Text1").Result = "911-1111"
Case Else
'Do nothing
End Select
End Sub
 
J

Johnny

Gre, I'm having trouble getting this to work. I followed your insructions but
I cannot get the phone number to popluate the text field that I specified.
Any suggestions. Thanks for your help.
 
J

Johnny

I want to put the phone number in the macro base on the person I select in
the drop down box. So the answer to your question is no. Hope you can help.
Thanks.
 
G

Greg Maxey

Johnny,

It works. In my example you have to have a dropdown field with the
bookmark name "Dropdown1" and a text field with the bookmark name
"Text1" or change the code to match the bookmark names of the dropdown
and text field that you are using. To check or change field bookmark
names you will need to unprotect the form and double click on the
fields.

You need to set the macro to run on exit from the dropdown field.
 
G

Graham Mayor

In that case Greg's solution works. Set his macro to run on exit from the
dropdown field (which is called dropdown1 here) set the case options with
the names and associated numbers

Case Is = "Bob"
oFld("Text1").Result = "867-5309"


and the result (here 867-5309) is pasted into field Text1 (not a drop down
field), You must TAB out of dropdown1 for it to work.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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