[dba-Tech] Filling Word fields

Bryan Carbonnell carbonnb at gmail.com
Thu Aug 16 13:29:16 CDT 2007


On 8/16/07, Susan Harkins <ssharkins at gmail.com> wrote:
> I have a reader that wants to fill Word fields based on the selection of
> another field -- sort of like choosing a Zip code and having code fill in
> the appropriate city and state. This is easily done in Access and if
> necessary, I could use Access to drive the whole thing. I'm wondering if
> this can be done in Word without involving Access? Has anyone done anything
> like this before?

No, but I just knocked together a quick and dirty example (sent
off-line as well).

Assuming that the document has 2 text form fields, one called Text1
and the other called Text2 you could have Text1 run the following
Macro in the OnExit property which would update the text in Text2

Public Sub sPickNumber()

Dim doc As Document
Dim intNumber As Integer

intNumber = Val(ThisDocument.FormFields("Text1").Result)

Select Case intNumber
  Case 1
    ThisDocument.FormFields("Text2").Result = "One"
  Case 2
    ThisDocument.FormFields("Text2").Result = "Two"
  Case 3
    ThisDocument.FormFields("Text2").Result = "Three"
  Case 4
    ThisDocument.FormFields("Text2").Result = "Four"
  Case 5
    ThisDocument.FormFields("Text2").Result = "Five"
  Case Else
    ThisDocument.FormFields("Text2").Result = "Invalid Entry"
End Select

End Sub

Basically what it does is puts the text for the numbers 1 through 5 in
Text2 depending on the numerical value of the entry in Text1.

-- 
Bryan Carbonnell - carbonnb at gmail.com
Life's journey is not to arrive at the grave safely in a well
preserved body, but rather to skid in sideways, totally worn out,
shouting "What a great ride!"



More information about the dba-Tech mailing list