PDA

View Full Version : Linked fields in Word



btmccarthy
12-05-2006, 12:30 PM
Hi all,
I'm brand new to VBA and need help with a linking fields in a form I'm building in Word 2003. Long story, short: I'm creating a form and have saved it as a template. I have multiple fields but I want to link two of them. The first field is named "faxname" and is a drop down menu of people and companies we commonly fax. Now, there is another field elsewhere in the template called "faxnumber". I would like to be able to link the two so when the name is selected from the first list, the fax number automatically appears.

Thank you for your help!!!!!
Regards,
Btmccarthy:beerchug:

fumei
12-05-2006, 06:05 PM
This is not really "linking", although I can see why you phrase it like that.

It is conditional logic.

IF Dropdown1 Item1 (Bob) is selected, THEN
xxx-xxx-xxxx appears elsewhere.

IF Dropdown1 Item2 (Harry) is selected, THEN
yyy-yyy-yyyy appears elsewhere (but at the same place).

Correct?

OK. Can do.

What exactly is " another field elsewhere in the template called "faxnumber"".

A field? A bookmark? A formfield?

There are a couple of ways to go about this. Say the FaxName dropdown is named...FaxName. (BTW: I hope you are giving explicit names for your stuff!).

If it is a FormField dropdown - you do not state what kind of a dropdown it is....you can use an OnExit macro for it.

Sub SetFaxNumber()
' declare object for ALL formfields
Dim DocFF As FormFields
' declare object for specific formfield
Dim oFF As Word.FormField

' set object for ALL the formfields
Set DocFF = ActiveDocument.FormFields

' set object for specific formfield
Set oFF = DocFF("FaxName")

' use logic on the result of specific formfield
Select Case oFF.Result
Case "Bob"
DocFF("FaxNumber").Result = "555-512-6234"
Case "Harry"
DocFF("FaxNumber").Result = "444-123-4567"
Case "General Motors"
DocFF("FaxNumber").Result = "666-666-6666"
' etc etc
End Select
End SubIf this is the OnExit macro for the formfield FaxName, then it picks up the Result, and depending on the result, sets a text formfield (FaxNumber) with the number.

There are certainly other possible avenues.