none
Content control/XML events RRS feed

  • Question

  • I am using Word 2010, Sharepoint 2010, and an Infopath 2010 Document Information Panel (DIP).  Fields in the DIP are included as Quick Parts/Content Controls in a Word document. 

    I have rules in the DIP that set values in other DIP fields which are then reflected in the Content Controls within the Word document.  I need those changes in the content controls that come from the DIP changes to initiate Word VBA macros.  Because the Content Controls are Sharepoint fields/columns, they are already bound to custom XML parts so I think I should be able to use the ContentControlBeforeStoreUpdate and the ContentControlBeforeContentUpdate events.  (The ContentControl_OnEnter and ContentControl_OnExit events don't work because the changes in the Word document don't come from the user actually doing something in the Word document.)

    Am I correct that the ContentControlBeforeStoreUpdate and ContentControlBeforeContentUpdate events are available to me when a change made in the DIP causes a change to a ContentControl in the Word document?  If so, how do I figure out which event is the right one to use?  And is the syntax I use to call the event exactly the same as when I use the ContentControl_OnExit/OnEnter events?  Or is there something special I need to do to refer to the XML side of things?  (I am a beginner on XML so I'm hoping that's not the case.)

    Thanks in advance for any ideas you can give me.  Carol.

    Thursday, June 12, 2014 3:33 PM

Answers

  • Sorry for the late reply.  I ended up using a WindowSelectionChange event.  It provides the functionality I need although that comes at the expense of the user experience (a bit) because the User has to click inside the document itself before any change happens to the document itself.  There just didn't seem to be any other way to do this...

    Thanks again to everyone who responded.  Carol.. 

    Monday, August 11, 2014 3:48 PM

All replies

  • Hi Carol,

    >> I have rules in the DIP that set values in other DIP fields which are then reflected in the Content Controls within the Word document

    ContentControlBeforeContentUpdate: Occurs before updating the content in a content control, only when the content comes from the Office XML data store.

    The event will be triggered successfully, but I’m afraid you are not able to change the content control value in this event handler (a runtime error will pop-up if you set the value of content control, the object model command is not available while in the current event).

    >> And is the syntax I use to call the event exactly the same as when I use the ContentControl_OnExit/OnEnter events?

    The syntax should be the same as “ContentControl_OnExit/OnEnter” events.

    For a workaround, you could consider to use a macro to set up values of content control before saving the document.

    Sub SetUpCotentControlVlaues()
        Me.ContentControls(1).Range.Text = "Title"
        Me.ContentControls(2).Range.Text = "Keywords"
    End Sub

    Hope it will help.

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 13, 2014 7:53 AM
    Moderator
  • Thanks, Jeffrey.  I don't need to change the value in the Content Control, I just need the change that's made via the DIP to trigger other events in the Word document.

    I'll give this a try and will let you know how it goes.  Thanks again.  Carol.

    Friday, June 13, 2014 12:08 PM
  • Well, I guess I still don't have it because I can't get the event to fire when the text is changed either via the DIP or in the Word document.  Here's my VBA code (with MsgBox's to see if the event firest):

    Sub ThisDocument_ContentControlBeforeStoreUpdate(ByVal CC As ContentControl, Cancel As Boolean)

    Select Case CC.Tag
        Case Is = "AcquisitionOrAssistText"
                If CC.Range.Text = "Assist by TNC" Then
                    MsgBox ("Acq was chosen")
                Else
                    MsgBox ("Something else was chosen")
                End If
        End Select
    End Sub

    (I can get the Document_ContentControlOnExit event to fire so I know I've gotten the CC.Tag right.)

    Any help will be appreciated.  Thanks.  Carol

    Friday, June 13, 2014 1:17 PM
  • Okay, there was something wrong with my syntax.  I found an old post that reminded/told me about choosing Document and then the event while in VBA to get the correct syntax for an event.  And now my events are firing!!

    Whoo hoo!  Thanks again, Jeffrey and others.  Carol.

    Friday, June 13, 2014 1:40 PM
  • Well, I spoke too soon.  I have found that I can get the ContentControlBeforeContentUpdate event to fire BUT I can't get the ContentControlBeforeStoreUpdate event to fire. 

    The "...Before..." event won't work for me because it responds to whatever was in the ContentControl BEFORE it was changed.

    Any ideas why one event would fire and the other wouldn't?  Thanks.  Carol

    Friday, June 13, 2014 2:25 PM
  • I did some more testing and found that I can only get the ContentControlBeforeStoreUpdate to fire if I make a change in the Word document itself. 

    I'm hazy about the difference between when the "BeforeContentUpdate" and "BeforeStoreUpdate" events happen so can anyone explain what is actually happening (probably at the XML level) when these two things happen?  That might help me figure out how to be able to do what I need to do.

    Thanks.  Carol

    Tuesday, June 17, 2014 7:17 PM
  • Hi Carol,

    According to the document Working with Content Controls:

    ContentControlBeforeContentUpdate: Occurs before Word updates the content in a content control.

    ContentControlBeforeStoreUpdate: Occurs before Word updates the contents of a content control from data in the document's data store.

    Please run the code below and let me know the test result on your side.

    Private Sub Document_ContentControlBeforeContentUpdate(ByVal ContentControl As ContentControl, Content As String)
        Debug.Print "Content Control before Content Update"
    End Sub
    
    Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
        Debug.Print "Content Control before Store Update"
    End Sub
    
    Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
        Debug.Print "Enter"
    End Sub
    
    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
        Debug.Print "Exit"
    End Sub

    Below is the expected result:

    Change the content in the Content Control

    Enter

    Content Control before Store Update

    Exit

    Content Control before Content Update

    Change the content in the Document Information Pane

    Content Control before Content Update

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, June 19, 2014 3:34 AM
    Moderator
  • Well, Jeremy, here are my results:

    Changing the content in the DIP -- 2 "Content Control Before Content Update"

    Changing the content in the Word document -- 1 "Content Control Before Store Update" and 2 "Content Control Before Content Update"

    As I said before, the "BeforeContentUpdate" event doesn't work because it only knows what the value of the Content Control is before it is changed.   And since the DIP change doesn't do the "BeforeStoreUpdate" event, it looks like I might just have to tell users to do the change in the document itself and not in the DIP.

    I know there was a reason why they didn't want to do that but I can't remember what it was at this time.  So I guess I'll check and see what they think.

    At least we now know our options.  Thanks again, Jeremy.

    Thursday, June 19, 2014 1:12 PM
  • Assuming that the fields in the DIP are all associated with the CustomXMLPart created by SharePoint, have you considered using the events associated with the Custom XML Part?

    I think it will need more research than I have (yet) done. Cindy may know more about what is actually practical. But for example, when you modify a value in the DIP, you should see a NodeAfterDelete event followed by a NodeAfterInsert event. However, if the user modifies the value in a content control linked to the node, you may see a NodeAfterModify event. Deletion of the value either in the DIP or a content control may raise a different sequence of events.

    (To process these events you have to 

     a. create a Class Module - let's call it cxpEvents with, e.g.

    Dim WithEvents cxp As Office.CustomXMLPart

    Private Sub Class_Initialize()

    ' In this case, I know which part contains the SharePoint column data.

    ' But typically, you would need to identify the one you need,

    ' probably looking for the Namespace

    ' http://schemas.microsoft.com/office/2006/metadata/properties

    Set cxp = ActiveDocument.CustomXMLParts(4)

    End Sub

    Private Sub Class_Terminate()
    Set cxp = Nothing
    End Sub

    Private Sub cxp_NodeAfterDelete(ByVal OldNode As Office.CustomXMLNode, ByVal OldParentNode As Office.CustomXMLNode, ByVal OldNextSibling As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
    MsgBox "Delete"
    End Sub

    Private Sub cxp_NodeAfterInsert(ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
    MsgBox "Insert"
    End Sub

    Private Sub cxp_NodeAfterReplace(ByVal OldNode As Office.CustomXMLNode, ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
    MsgBox "Modify"
    End Sub

    ' end of the class module

    ' Then you can (for exampe) put the following code in the Document's ThisDocument module.

    Private speh as SPEventHandler

    Sub AutoOpen()

    Set speh = New SPEvent

    End Sub

    (and so on).

    Or maybe you are using .NET (and VSTO)?


    Peter Jamieson

    Thursday, June 19, 2014 5:16 PM
  • Sorry for the late reply.  I ended up using a WindowSelectionChange event.  It provides the functionality I need although that comes at the expense of the user experience (a bit) because the User has to click inside the document itself before any change happens to the document itself.  There just didn't seem to be any other way to do this...

    Thanks again to everyone who responded.  Carol.. 

    Monday, August 11, 2014 3:48 PM