Content Control "OnChange" Event. Why is Microsoft dragging it's feet?

Yesterday I was tinkering in Word and my custom Document_ContentControlOnChange event

http://gregmaxey.mvps.org/word_tip_pages/content_control_custom_events.html

and developed a relatively simple method to use that technique to create mutually exclusive content control checkboxes:

http://gregmaxey.mvps.org/word_tip_pages/mutually_exclusive_content_control_option_buttons.html


I shared it with a long-time Word MVP and his comment was "Best thing I've seen in six months. Very Nice!"


I'm just a dabbler in VBA and I certainly don't consider myself a programmer.  If I am able to cobble together things like this, I can't understand why Microsoft won't incorporate a built-in Document_ContentControlOnChange event in the application!


I consider content controls the "crown jewels" of Word.  That said, and as versatile as they are, Microsoft has left them unfinished.  I know that there has been a call for a change event since the content controls were introduced in Word 2007?  Why after two versions later is it still glaringly absent?


Hoping some moderator/MS employee will see this and forward it to the product team and that the product team will finally take long overdue action fix it or at least explain why they can't/won't.


  





Was this discussion helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this discussion?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this discussion?

Thanks for your feedback.

<<
I know that there has been a call for a change event since the content controls were introduced in Word 2007?
>>

I wondered whether it might be because
 a. you can always detect a change as long as your controls are hooked up to XML data, using the ContentControlBeforeStoreUpdate (and I think that works with builtin properties as well as stuff in Custom XML parts)
 b. If you're having to write VBA anyway, it should always be feasible to create the Custom XML part and the XPath mappings that you need to achieve that
 c. a lot of the support for content controls was bound up with things that Microsoft wanted to do with .NET (VSTO) and SharePoint. If you are using SharePoint
 c. having events for both store update and content control change would probably mean that either Microsoft, or the individual programmer, or both would have to pay attention to dealing with store updates causing further control changes and so on.

IMO there are potential advantages to doing it using the StoreUpdate - you could for example construct your "exclusive check button" code in a way that relied on the structure of the XML rather than the tag names (e.g. when you want a group, you make your XML like

"<root><checkboxes cb1='false' cb2='false' cb3='true' cb4='false'/></root>


then have code like this:

Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
Dim cNode As Office.CustomXMLNode

If ContentControl.Type = wdContentControlCheckBox Then
  With ContentControl.XMLMapping
    If .IsMapped Then
      With .CustomXMLNode
        If .NodeType = msoCustomXMLNodeAttribute Then
          For Each cNode In .ParentNode.Attributes
            If cNode.BaseName <> .BaseName Then
              ' might have to deal with localization here
              cNode.Text = LCase(CStr(Not CBool(Content)))
            End If
          Next
        End If
      End With
    End If
  End With
End If
End Sub


But perhaps that doesn't cover all the ground?

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Peter,


Thanks for you interest and reply.  I can follow your code, but I'm not sure that I can implement it as I don't follow the XML.


However, this brings up another shortcoming (IMHO) with CCs.  While the event you mention does detect change in dropdown and check box CCs, it doesn't in text CCs (I didn't text with any of the others).   So yes, in theory for dropdowns and checkboxes, it is a pseudo change event, but when it fires you are very limited as to what you can do with it.


Consider the following.  Add a dropdown CC tagged DD, a checkbox CC tagged CB and a text CC tagged "Text" to a document and bind them to a customXMLPart.  Then add this code:


Change in either the dropdown or checkbox will trigger the event but a RTE occurs.  Change (real time change) in the text CC does not trigger the event. It is triggered only when the user exits the CC.


Private Sub Document_ContentControlBeforeStoreUpdate(ByVal CC As ContentControl, Content As String)
  On Error GoTo Err_Handler
  Select Case CC.Tag
    Case "DD"
      Select Case CC.Range.Text
        Case "Red"
          Selection.Paragraphs(1).Range.HighlightColorIndex = wdDarkRed
        Case "Blue"
          Selection.Paragraphs(1).Range.HighlightColorIndex = wdDarkBlue
        Case "Green"
          Selection.Paragraphs(1).Range.HighlightColorIndex = wdBrightGreen
      End Select
    Case "CB"
      Selection.Paragraphs(1).Range.Delete
    Case "Text"
      'Doesn't occur until you exit the event.
      Beep
  End Select
  Exit Sub
Err_Handler:
  MsgBox Err.Number & " " & Err.Description
End Sub


I'm not a SharePoint user so I am probably missing out on what usefulness these events may have, but for my purposes, at least until I can better understand and implement your suggestion, they seem almost useless.  :-(


Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Peter,


I've managed to create a working example of mutually exclusive checkboxes using a variation of your code.  One thing I had to change was adding an IF .Checked condition.  Otherwise if you check a box and then uncheck the same box, all the other boxes became checked.


I've posted the working version here:

https://dl.dropboxusercontent.com/u/64545773/Mutually%20Exclusive%20CC%20Option%20Buttons%20using%20mapping%20and%20built-in%20events.docm


While the BeforeStoreUpdate works and seems to work well for this application as a pseudo OnChange event, I still feel that MS is dragging their feet ;-)



Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Well, having looked around a bit more, I agree with you about the event support being pretty unhelpful for the sort of things you are attempting. Whether that has any bearing on the value of Word for Microsoft's big paying corporate customers and its revenue is probably a different matter.
 

2 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Discussion Info


Last updated July 31, 2022 Views 4,302 Applies to: