If statements and drop down menues 03

B

blwrs

I'm using word 2003. I currently have a dropdown menu named "Dropdown1"
which lists the names of some project foreman. I would like to set up
another area on my paper which automatically inserts each foremans phone
number when his/her name is selected from the drop down list. I have not
been able to make this work. please help! Also i'm by no means a Word expert
so you will have to really walk me through it. "go to here", "select this"
that kind of information would be great.
thank you.
 
D

Doug Robbins - Word MVP

There are a number of ways to do this, but none of them particularly simple
for a non-expert.

One reasonably simple way is to create autotext entries with the name of
each foreman each of which contains the phone number.

Then you would have the following macro run on exit from the DropDown
formfield

Sub GetPhone()
Dim myDrop As DropDown
Dim Foreman As String, PhoneNum As String
Set myDrop = ActiveDocument.FormFields("Foremen").DropDown
Foreman = myDrop.ListEntries(myDrop.Value).Name
Foreman = Mid(Foreman, InStr(Foreman, " ") + 1)
PhoneNum = ActiveDocument.AttachedTemplate.AutoTextEntries(Foreman).Value
ActiveDocument.FormFields("PhoneNumber").Result = PhoneNum
End Sub

It assumes that the DropDown that contains the names of the foremen has the
bookmark name of "Foremen" assigned to it and that there is another
formfield with the bookmark name of "PhoneNumber" in which the phone number
is to be displayed. It also assumes that your drop down contains the first
and the last name of each foreman and that the names of the autotext entries
are the last names of the foremen.

For information on setting a macro to run on exit from a formfield, see:

http://www.mousetrax.com/techpage.html#autoforms

To learn what to do with the code provided above, see the article "What do I
do with macros sent to me by other newsgroup readers to help me out?" at:

http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

If you happen to have two foremen with the same last name, the above method
will not be satisfactory

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

As an alternative to Doug's method you could insert the same autotext
entries by using an autotext field

To clarify, let's say that you have three foremen "Bill" "John" & "Fred" and
that these are the names as they appear in the dropdown field.
Check the calculate on exit checkbox of the dropdown field.

Save the details for each of the foreman with autotext names that are
identical to the names as they appear in the dropdown - so far this is the
same as what Doug suggested.

Where you want the information from the autotext entries reproduced insert
an autotext field eg

{ Autotext "{ Dropdown1 }" }

When you tab out of the dropdown field the autotext field will be updated
with the associated information.

If you wish to associate more than one piece of information with each
foreman then create a second autotext entry for each only this time add a
character to the autotext name eg BillA, JohnA, & FredA

You can then insert the second piece of information using another Autotext
field i.e. in this instance

{ Autotext "{ Dropdown1 }A" }


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

My web site www.gmayor.com

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

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