PDA

View Full Version : Run Time Error 5844



HTSCF Fareha
05-01-2021, 04:07 AM
I've occasionally been getting this error when running a macro enabled template.

28389

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
(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

gmayor
05-01-2021, 05:15 AM
What type of CC is the CC titled 'Four'?
What is the content of TextBox4 when this error occurs.

HTSCF Fareha
05-01-2021, 06:19 AM
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.

HTSCF Fareha
05-06-2021, 12:33 PM
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. :think:

gmayor
05-06-2021, 10:46 PM
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?

HTSCF Fareha
05-07-2021, 03:43 AM
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. :o:

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. :banghead:

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

gmayor
05-07-2021, 05:39 AM
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.

HTSCF Fareha
05-07-2021, 07:25 AM
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).

gmayor
05-07-2021, 09:38 PM
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.

HTSCF Fareha
05-08-2021, 03:46 AM
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 (https://docs.microsoft.com/en-us/office/vba/api/word.contentcontrol.multiline)

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

gmayor
05-08-2021, 03:59 AM
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).

HTSCF Fareha
05-08-2021, 07:57 AM
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. :thumb

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.:crying:

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.

gmayor
05-08-2021, 08:37 PM
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


28434

HTSCF Fareha
05-08-2021, 10:45 PM
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

gmayor
05-09-2021, 01:13 AM
You will need the RibbonX Editor - https://github.com/fernandreu/office-ribbonx-editor
See http://gregmaxey.mvps.org/word_tip_pages/customize_ribbon_main.html

HTSCF Fareha
05-09-2021, 02:52 AM
Many thanks, Graham! :thumb

HTSCF Fareha
05-10-2021, 02:28 PM
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. :banghead: 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