[dba-Tech] Filling Word fields

Susan Harkins ssharkins at gmail.com
Thu Aug 16 13:34:29 CDT 2007


OK, but what if there are lots and lots of possibilities -- like in the case
of zip codes -- can Word maintain a list on its own -- kind of like a
reference list or something? I don't even know the right terminology to use
for Word -- so I apologize. 

Thanks for the example Bryan. :) 

Susan H. 

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!"
_______________________________________________
dba-Tech mailing list
dba-Tech at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-tech
Website: http://www.databaseadvisors.com

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.19/953 - Release Date: 8/14/2007
5:19 PM
 




More information about the dba-Tech mailing list