Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF field - Document Automation

Status
Not open for further replies.

dcurtis

Technical User
May 1, 2003
273
US
I am using Word 2003, SP3. I have a dropdown list in a document that I want to control the text in a field later in the document. I inserted an IF field from the Document Automation list and set the parameters. My problem is that I want the IF field to update as soon as the change is made to the dropdown list, much like an AfterUpdate in Access. Is that possible in Word?

I would search this forum, but the option isn't working right now, at least for me
 
what kind dropdown?

if activex combobox (dropdown), and use bookmark (not IF field); ComboBox_Change event change bookmark text on fly

Code:
Sub ComboBox1_Change()
Dim sBookmark As String
Dim sNewText As String
sBookmark = [i][b]YOURbookmarkName[/b][/i]
sNewText = ComboBox1.Text
Selection.GoTo what:=wdGoToBookmark, Name:=sBookmark
Selection.TypeText Text:=sNewText
' above deletes bookmark locator/name
' so select inserted text
' recreate bookmark (w/ same name) with new text 
Selection.MoveLeft Unit:=wdCharacter, Count:=Len(sNewText), Extend:=wdExtend
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:=sBookmark
    End With
End Sub

bookmark text always = combobox (dropdown) text, even on doc_open - doc_open fires change event. change dropdown, bookmark text changes immediately; activex combo populate from doc_open: sample

Code:
Private Sub Document_Open()
ComboBox1.AddItem "One"
ComboBox1.AddItem "two"
ComboBox1.AddItem "three"
ComboBox1.AddItem "four"
ComboBox1.AddItem "five"
ComboBox1.AddItem "six"
End Sub

must be in ThisDocument
 
what kind dropdown?

if activex combobox (dropdown), and use bookmark (not IF field) Change event change bookmark text on fly;

Code:
Sub ComboBox1_Change()
Dim sBookmark As String
Dim sNewText As String
sBookmark = [i]bookmarkName[/i]
sNewText = ComboBox1.Text
Selection.GoTo what:=wdGoToBookmark, Name:=sBookmark
Selection.TypeText Text:=sNewText
Selection.MoveLeft Unit:=wdCharacter, Count:=Len(sNewText), Extend:=wdExtend
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:=sBookmark
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
End Sub

bookmark text will always = combobox (dropdown) text, even on doc_open as doc_open fires change event. change dropdown, bookmark text changes immediately
 
If you set the 'calculate on exit' property of a drop-down formfield to true, and your IF field tests the drop-down formfield's bookmark value, the results will update as soon as you tab out of the formfield. Is that not enough?
 
Macropod - I set the dropdown to Calculate on exit and wrote the if to check it, I think. The syntax is:
Code:
IF  txtAgency = "AVALUE" "One" "Two" \* MERGEFORMAT

I didn't add the \* MERGEFORMAT - Word automatically adds that and I can't seem to get rid of it.

After I update the dropdown (with the form locked), the If field doesn't change. Am I on the right track?
 
Ordinarily, your drop-down field's bookmark within the IF field should be contained in a REF field, like:
{IF{REF txtAgency}= "AVALUE" "One" "Two"}
or
{IF{txtAgency}= "AVALUE" "One" "Two"}
where the field braces '{}' are created via Ctrl-F9.

Cheers
 
I used your code and when I toggle the field code off the following message is displayed

Error! Missing test condition

This is the exact code I put in the field:
Code:
{IF {REF txtAgency}="Listen" "Listen, Mentor" "VSAC, Loan"}

Thanks again for your help. I'm sure it's something easy and obvious I am missing.
 
Your field coding looks OK and works for me. What properties are you using in the drop-down field?

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top