Consulting

Results 1 to 17 of 17

Thread: Run Time Error 5844

  1. #1
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location

    Run Time Error 5844

    I've occasionally been getting this error when running a macro enabled template.

    Error.jpg

    It doesn't happen every time, but when it does, it occurs on this line of code as shown in bold.

    For Each oCC In ActiveDocument.ContentControls
                Set oRng = oCC.Range
                Select Case oCC.Title
                    Case "One"
                        oRng.Text = .TextBox1.Text
                    Case "Two"
                        oRng.Text = .TextBox2.Text
                    Case "Three"
                        oRng.Text = .ComboBox1.Value
                        oRng.Font.Color = .ComboBox1.BackColor
                    Case "Four"
                        oRng.Text = .TextBox4.Text
    .......
    The only thing that I can add that might help in solving this issue, is that text is pasted into TextBox4, after being copied from another bespoke source, prior to pressing the proverbial "Enter" button to commit the TextBox / ComboBox entries to the word document.

    The only thing that I have found online seems to reference carriage returns which might have something to do with this?
    https://social.msdn.microsoft.com/Forums/en-US/a6e801ca-2d12-4a66-8df4-734f15cf4333/linebreak-in-contentcontrol?forum=innovateonoffice

    Unfortunately I cannot provide any copy examples of the text that is causing the issue because this was work based.

    I don't know if there is something codewise that can be done to alleviate the error?

    Many thanks!
    Steve

  2. #2
    What type of CC is the CC titled 'Four'?
    What is the content of TextBox4 when this error occurs.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    Thanks, Graham.

    The CC is Rich Text.

    The content is a few lines of text made up of sentences and paragraphs.

    Clicking on Debug when the error occurs gives the line previously mentioned. Clicking End will populate the document upto that CC.

  4. #4
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    I've experimented with skipping on errors here

    For Each oCC In ActiveDocument.ContentControls
                Set oRng = oCC.Range
                On Error Resume Next
                Select Case oCC.Title
    Okay, so if there is an error with TextBox4 it keeps going leaving the area of the form blank. This is expected, but highlights the error. But interestingly, it would appear that ocasionally TextBox8 has the same issue. I've not had any of the other TextBoxes throw up an error.
    Attached Files Attached Files

  5. #5
    While I was unable to reproduce the problem, I have modified your process to use more meaningful control names, and have changed one of the content control titles.
    I noticed that two of the content controls were unused. One of them seems to relate to an unused text box on your form. I am unsure about the other.
    Next time the error occurs can you establish exactly what was in the text box?
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  6. #6
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    You are spot on with giving the control names more meaningful names. Although I was going to do that when the form was working as expected. I guess that common sense and good practice should mean doing this from the off.

    Admission number two and my bad, I zipped up an old version of the form. Shouldn't upload last thing at night. Sorry!

    I've now deleted all my "old" development copies (I will learn!) and have amended the correct one with sensible control names. Annoyingly, this has now broken my prompt box that should appear with populated text when a button is pressed.

    Could these prompt buttons / TextBox be causing the issue???

    The bold text is not always required, so this doesn't require a prompt box to complete. That being said is there a way to add a couple of words to make bold anyhow that a user doesn't have to enter in the relevant box (i.e. Priority, Essential)? This is to avoid the user forgetting to put these in. I'd still need the option to add other words, but without these predetermined ones showing in the textbox.

    Many thanks as ever for your assistance and patience, Graham.

    Steve
    Attached Files Attached Files

  7. #7
    The buttons don't reveal the texts because you have referred to the wrong controls.
    The default word set are added as a string variable, to which the contents of the text box are added before splitting.
    See attached.
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  8. #8
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    Many thanks, Graham. It really helps when you comment out the error lines. Makes it much easier to see where I had gone wrong. Really appreciate this!

    I think that I've also managed to replicate the error!

    If you type some words in either of the threat, harm, opportunity or risk text boxes, but add a double line space, then add some more text, this produces the error (or rather an empty content control on the document).

  9. #9
    To eliminate the errors, put the content controls on their own lines, or if you want them both on the same line, put them in two cell borderless tables.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  10. #10
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    Thanks, Graham.

    I tried putting the content controls in a borderless table first. This didn't work and still produced the error.

    Then I tried putting the content controls on separate lines and yes, this did work and allowed having paragraphs without the error, but unfortunately this is not an ideal result for the layout of the finished form.

    Having a browse online I stumbled across the mention of ContentControl.MultiLine property

    Would this work somehow to overcome my error code and allow multi-line with the RichText content control?

  11. #11
    The multiLine property is for PlainText controls.The problem relates to having the two controls in the same paragraph.
    See attached, which works.
    As we are on full lockdown here and only allowed out once a day with permission by SMS (until Monday); with time on my hands I also included a ribbon tab and with it the ability to edit the document).
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  12. #12
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    Wow, many thanks Graham! This is a completely different approach and I really like the cosmetics applied and the option to go back to the document to be able to edit.

    The layout does of course allow for the paragraphs etc., albeit with a bit of a gap between the level being selected and the descriptive text that is input by the user.

    Alas, when testing the form entering "this is a test" for each of the text boxes on the form, then selecting "this" and "test" for words to be made bold (ensuring the use of a comma), this then had the result of making the entire phrase "this is a test" being made bold in all the text boxes on the form and not just the 'Research' text box.

    Gutted that you are still on full lockdown. It's been bad enough over here, but at least we are starting to be allowed out and about a bit, providing that we follow the strict guidelines that the government have put in place.

  13. #13
    The lockdown is relaxed tomorrow, even though we have the highest infection rate in Europe. Given that we have been in lockdown since last November, clearly it is a ploy that doesn't work.

    I don't see the issue with the bold (see illustration). It probably relates to the style used; however if you add the line indicated below it may help.

    .Show
    If .Tag = 0 Then GoTo lbl_Exit
    sBoldList = Split(sBold & .txtBoldList.Text, ",")
    oDoc.Variables("BoldList").Value = .txtBoldList.Text
    oDoc.Variables("Missed").Value = .OptionButton2.Value
    For Each occ In oDoc.ContentControls
    Set oRng = occ.Range
    oRng.Font.Bold = False


    2021-05-09_06-29-06.jpg
    Last edited by gmayor; 05-08-2021 at 10:39 PM.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  14. #14
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    Many thanks, Graham.

    I'll add this line. To be honest, the form would only start to play up if one went back to it a couple of times, then edit it a bit each time. After a couple of edits this little gremlin would sneak in.

    Over here getting the vacine roll out seems to have kerbed the infection rate considerably. It's been an amazing effort by the health staff to get so many people at least their first jab of the two in such a short space of time.

    Of course you have now got me interested in the ribbon buttons. Looks like you need an external editor to create / edit these?

    Steve

  15. #15
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  16. #16
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    Many thanks, Graham!

  17. #17
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    I used the form for real earlier today and that annoying error came up again for the bottom TextBox on first use. Going back in to "edit" the document, the CC wording had placed itself inside the aforesaid TextBox. The text originally entered was just four sentences that were split equally with one paragraph.

    The only tweak that I made to the V2 template was to split the table holding the Threat, Harm, Opportunity and Risk into four separate ones so that the cell widths could be adjusted individually.

    The only other thing is that this document's text once produced is then copied and then pasted into a bespoke programme that is in Rich Text Format. This is when the previously hidden table lines show themselves again. Not sure if there is a way of surpressing these or not? My gut feeling is the latter, otherwise the macro enabled document would fail. Although I am usually surprised about what solutions can come out of this forum!

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •