none
Broken References to document click events in vba RRS feed

  • Question

  • Not sure if this forum handles vba questions but I have a macro enabled document which is referencing a custom template(dotm) and most of the document events work fine. However, we seem to have lost the association between the docm labels click and the label_click event code in the dotm. If I double click the label control while in design mode it tries to re-create the event code in the docm's thisdocument module as opposed to showing me the dotm code. Any idea how to fix this as it impacts many documents.

    thanks.

    Thursday, November 13, 2014 3:42 PM

All replies

  • Hi Beruken,

    >> If I double click the label control while in design mode it tries to re-create the event code in the docm's thisdocument module as opposed to showing me the dotm code<<

    Did you mean that you wrote a class module for labes's click event in custom template?

    Based on the desription, if you click the lable control in design model, the Word application would create click event for this lable in that document.

    As far as I know, this is a default behavior provide by Word application. It helps users to create event quickly and easily.

    If I understood correctly, I think it is hard to achieve the goal because it if diffcult for Word application to know where we add the event for the lables.

    Regards & Fei


    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, November 14, 2014 2:27 AM
    Moderator
  • Fei, No I did not write a class module. We started out with a dotm that has both the visual controls and supporting event code in the ThisDocument class file. We created a new document based on the dotm and saved as a DOCM. The new document now references the template via a web path as it is part of a sharepoint library. New macro enabled documents are then created from the docm and this leaves the reference to the dotm intact. All code is executed via the the dotm, wether it is a macro or a controls click event.

    The click events were mistakenly cut and pasted from the dotm thisdocument module and placed in another module. This effectively broke the association to the docm for those specific controls even though it was restored. And this is only for existing documents created with the association to the dotm. 

    Iif I try double clicking the docm label control, it does as you state and creates the click event procedure in it's own thisdocument module, but it errors when executing the event as it knows the referenced dotm has a duplicate event handler. It just won't fire the dotm version. This also happened with the Document_Open procedure without any code changes. For some reason that event stopped firing and I had to fix that by moving the code to a new module using AutoOpen().

    I guess my question is, somewhere in the docm control properties there has to be a reference to the controls click event to tell it what event it is associated with. So, how can I restore that?

    I tried accessing the controls via ActiveDocument.Fields and executing a loop to test for label controls which works fine. However when debugging I can't see any properties or references to which event that control is wired to. In .net it is an easy task to tell the control which code it executes within a click event though it is usually embedded in the definition of the page.

    I hope I explained this well. Thanks

    Ken


    • Edited by Beruken Friday, November 14, 2014 12:41 PM make response easier to understand
    Friday, November 14, 2014 12:17 PM
  • Hi Ken,

    >>If I try double clicking the docm label control, it does as you state and creates the click event procedure in it's own thisdocument module, but it errors when executing the event as it knows the referenced dotm has a duplicate event handler. It just won't fire the dotm version<<

    Thanks for the detail explaintation for the issue. However, I failed to reproduce the issue. As far as I tested, there is no errors, the event in the docm would be fired at the first time, then the event in dotm.

    I tested in Word 2013, here are my steps:
    1. create a document and insert a lable control. Then add click event for it.

    2. save the document as Word template

    3. create a new document based on the custom template

    4. double click the label control in design modle(it wolud create an click event in the document)

    Did I miss any steps?

    Regards & Fei


    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.

    Monday, November 17, 2014 9:20 AM
    Moderator
  • Fei, thank you for your time on this. Yes, I think the missing point is my dotm based vba click events are not firing anymore. This was true for the Open_Document procedure too.

    I don't want any event handlers or code in the docm vba. We need to manage the code and changes globally, outside of the individual documents. I included the test case (label click event in the docm) to show that the corresponding dotm vba click event is recognized by the compiler but not executed.

    I think the question now is... How can I get the DOCM to execute the referenced dotm Open_Document and Label click events it once used too?

    Please note, I'd rather not have to recreate the events in the docm and have them call on the dotm code as there are some 80+ documents that follow a monthly approval process.

    Monday, November 17, 2014 1:07 PM
  • Fei, as it turns out we are going to update the 80 documents to use a better method for referencing the controls and events by breaking the dependency on the click events in the dotm and calling dotm macros from the docm click events. As it should have been from the start.

    Thank You for your time.

    Monday, November 17, 2014 4:15 PM
  • I also tried to replicate this problem. I have only been looking at the _Click events.

    The only way (so far) that I have been able to get the behaviour you describe is to delete the Label objects from the .dotm's document surface, but leave the _Cllick event handlers in the ThisDocument of the .dotm. In that case, recreating a control with the same name "re-enables" the event.

    I don't suppose that is the situation you have, but I thought I'd mention it just in case.


    Peter Jamieson

    Monday, November 17, 2014 4:17 PM