if-statementms-wordfieldcodes

Using XML Mapping Pane with IF Field Code Word Document


I have been trying to use the content control from XML Mapping Pane with the IF Field Code. But I am having some issues. It seems that i am not being able to compare the value of the content control with what i want

For example:

{ IF Language_CodeValue <> "DAN" "ENGLISH" "DANISH" } 

Language_CodeValue being a content control from the XML Mapping Pane. Any help would be appreciated. The Language_CodeValue do contain DAN in it when i display it on a word document. Seems like the comparison with string which is not working


Solution

  • Content controls cannot successfully be nested within field codes of any kind. They don't work correctly.

    When you think about it logically, this makes sense because when a field updates the only thing it can show is the result, which means the content control can't be used. Or if it could be used, then the IF field cannot function correctly. So basically field codes need to ignore content controls.

    There's no simple workaround for this, but one possibility would be to use the ContentControlBeforeStoreUpdate event of the Document object to run object model actions when the XML node in the Custom XML Part is changed. It can write its content to a CustomDocumentProperty. A DocProperty field can then be nested in the If field.

    Once you've successfully mapped the content control to the custom xml part the ContentControlBeforeStoreUpdate event can be triggered. This event is (must be) defined in the ThisDocument module of the document containing the content control.

    In the VBA editor double-click ThisDocument for the document containing the content control in the Project window. From the list at the top left of the code window choose "Document". From the list at the top right choose ContentControlBeforeStoreUpdate. This will insert the Sub...End Sub stubs for the event.

    Private Sub Document_ContentControlBeforeStoreUpdate( _
                ByVal ContentControl As ContentControl, _
                Content As String)
      Select Case ContentControl.Title
        Case "Tree"
            ActiveDocument.CustomDocumentProperties("test").Value = Content
        Case Else
      End Select
    End Sub
    

    Note that all content controls linked to a custom xml part will trigger this event. You should, therefore, check the title (or tag) property of the content control and branch the appropriate actions.