Is there a way to detect changes to the content control in word in office js? - ms-word

I've got a script that finds all matching bits of text and puts them in a content control. I noticed there was a functionality to remove the content control if the text was edited ContentControl.removeWhenEdited = true. Is there a way to run this same trigger/event of when the text content changes, but instead of removing the content control trigger some custom code instead?
I figured since there's already functionality to trigger on the exact event I need, it surely can't be too complicated. I tried ContentControl.onDataChanged = MyFunction() but this only ran the function when the content control was added and couldn't rerun it when the data was infact changed.
Any and all help greatly appreciated!

Related

Manage image deletion in a WYSIWYG editor

When an HTML editor is used and images are added from the local computer, they are uploaded to a server and a link is obtained to put it in the image src attribute. What happens when the img element is removed from the editor? How would the image be deleted from the server? In this case I understand that the image deletion event could be detected and then call a service to delete it. But what happens if the user adds a new image and leaves the page? How would it be deleted in these cases?
In both cases, if the deletion of the images is not managed, it could happen that the server is filled with unused images. How do you usually solve this problem? How is the proper way to solve this?
That's a nice question there. And yeah, for sure the server would fill up with unused images in some point. I'm not an expert on this but I'll try to suggest something so I can implement it too in my WYSIWYG editor haha. I suppose you have a custom modal for the insertion of the image. Upon clicking the button you could save the image link to an array and at SAVE || on leaving the document edit || on popstate event you could make a regex that checks the innerHTML of the editor for the specific SRC. If is not found then you could push an ajax request with the image name so you can deleteit. For sure there are more efficient and complex ways to achieve that. Such as creating text ranges and track elements on keydown - Backspace(8) / Deletekey(46).
An other way is that you could track the images that are in use. When the document is saved regex out the images in the document, push them to a db table and periodically make a check from the back end so you can delete those that are not in use.
I don't know if my suggestions are helpful or not. I just saw an interesting subject so I jumped in. Cheers mate.

MS Access 2013 textbox update macro

What I am trying to accomplish:
Use button to open a form, filter the form, and set specific value to an unbound textbox in the opened form's header. There are multiple buttons being used open the same form and I would like this textbox to changed every time a specific button is clicked.
What I have done so far:
Used a macro to open the form and the "where" condition to filter the records. I also used "SetProperty" to change the value of the unbound textbox in the opened form's header depending on which button was clicked. When I do used the SetProperty option in the macro I get the error "The control name ... is misspelled or refers to a control that doesn't exist. Error 32004
I have verified numerous times that this is the correct name for the textbox and everything. I am pretty new to access and don't do VBA all that much so any assistance would be greatly appreciated. Thanks.
First Form and Macro for the "Physical Security" Button
Second form with error and unbound txt box I want to change to "Physical Security"
A few Ideas to track down your problem:
Maybe there's a problem with opening and (immediately) accessing the forms controls(?) You could try to fire a macro from within the same from that (only) changes the value of this text-box to make sure it definitely works there. Of course you'd want to make it work there if it failed before you'd go back to your original problem.
Is the property called value? Could it be text?
Are you sure you need to separate (all) hierarchies using !? Just by desperation: Maybe try using Forms!frmVW.txtXY or Forms.frmVW.txtXY
If that doesn't solve it:
It's often best to reduce your problem to it's very basics. Copy your application (!!!!) and radically delete unneeded stuff. Or start a short experiment from scratch (one or two forms, maybe only a button and a textbox, a macro, most probably not even a single Datatable/Source).

MS-Access 2007 Form cannot edit data until Form changed to Design View & back to Form View

Update: Manually losing the form and re-opening it also causes editing to be allowed, please see Step 4 below and "Additional Notes" section below. Thanks!
An MS-Access 2007 database that I have simplified a great deal during troubleshooting still has the same problem:
Restart Access and open the database
The autoexec calls a vba function that initializes some TempVars, then opens a form with: `DoCmd.OpenForm FormName:="MainEditor"
All Bound and Un-Bound Text Boxes and Combo Boxes display their data
correctly, but NONE of them can be edited. Keystrokes are ignored, pull-downs on Combo Boxes display lists of choices correctly but no choice can be selected.
Change the form's view to Design View, then immediately change it back to Form View. Alternatively, manually close the Form and then re-open it.
All the controls continue to display their data correctly, but now ALL of
them can be edited normally.
After changing to Design View and back to Form View, the Form is editable normally until Access is shut down and restarted.
Additional Notes:
I tried adding a DoCmd.Close and a DoCmd.FormOpen immediately after the original DoCmd.FormOpen in the startup function called by the Autoexec macro, but the Form remained unable to accept edits. Manually closing the form, and then manually re-opening it, seems to work every time. Is there any chance that Access needs a delay to process before opening the form, and manually doing the close/open cycle provides that time window?
Here's some background:
The Table has a primary index, 4 other indexes, and one-to-many relations to 7 other tables.
The Form's Record Source is the Table, and Allow Edits = Yes.
All the controls on the Form are set: Enabled = Yes, and Locked = No.
There are no sub-forms, only the one Form.
This isn't much to go on. If you ask for further specifics I'd be glad to provide them.
Thank you. Dave
Instead of using an Autoexec macro, specify a startup form.

Restrict MS Word Content Control Functionality

I have a MS Word document and that document has multiple content control. When user copies entire data from one content control to another sometimes it copies content control itself with data and when user pastes data it creates nested content control.
Question:
Somehow I need to restrict Word document so that user can only modify data and additional content control cannot be created. How can I achieve this.
I don't think there is a setting in Word that can control this; there isn't a content control property that does.
So I think you're looking at a VSTO Word Add-In, or possibly a VBA macro.
With VSTO, have a look at the content control event model. Maybe Document.ContentControlAfterAdd fires on paste? Googling .. apparently it does, subject to an issue
when the content controls are in table cells, and the user chooses to
insert a column: the BeforeDelete is fired for all the content
controls in the table, but AfterAdd is not raised when the column
insertion completes.
Check out the other content control related events as well - start by seeing which fire when the user does what you are concerned about, and of course, what other situations they fire in (which your code will have to ignore).
Otherwise, you could try a more generic way of capturing paste. There is:
this thread
and the keyboard hook approach

jQuery Show/Hide divs using same class not working because of html.push?

The object is to Show-Hide text located under their respective Titles, so a User reads the title and shows or hides text belonging to that title if the User wants to read more.
I tried whatever I could find so far on here, we're talking dynamically setting text coming from a spreadsheet, can't use IDs, must work with .class, must be missing something, I have this piece of code:
... html.push('<div class="comments">' + comment + '</div></div></div>');
but when I try this Show-Hide code nothing happens, even if the error console shows nothing. Basically I want to Show-Hide the .comments class divs with a show-hide toggle link located under each of them. I say them because the .comments divs are reproduced dynamically while extracting text coming from Google spreadsheet cells/row (one .comments div per spreadsheet row). I tried .next, child and parent but they all divorced me so I dunno looks like a dynamic issue. So far I only managed to globally toggle all divs to a visible or hidden state but I need to toggle independantly individual divs.
I prefer a jQuery solution but whatever worked so far was achieved with native javascript.
Note: If a cross-browser truncate function which would append a more-less link after a number of words (var) in each .comments divs would be easier to implement then I would gladly take that option. Thx for any help, remember I am still learning lol!
I have been working on an entirely JS UI project and have brought myself to using $('', { properties }).appendTo(BaseElement) to work best for adding HTML elements because it appropriately manipulates the DOM every time.
If you are having good luck with push elsewhere, however, breakpointing on the line where you do your $('.class').hide() and see what $('.class').length is. Alternately, you can just add alert($('.class').length) to your code if you are unable to breakpoint the code. If it is 0, then your elements have not been properly added to the DOM. Changing to append will ensure they are part of the DOM and therefore targetable via JQuery.