Solved HTML tags showing up out of nowhere!!! (1 Viewer)

ThomasDirkse

New member
Local time
Today, 00:35
Joined
Apr 6, 2023
Messages
11
I have a table with a text field (Short Text). Also, I have a form that displays the contents of that text field. On some records the text is displayed with the HTML tags: "<div>my text</div>". These HTML tags are not part of my text. Where are these tags coming from? Does anyone know?
I am running MS Access 365.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:35
Joined
Sep 21, 2011
Messages
14,299
How are those fields populated?
 

isladogs

MVP / VIP
Local time
Today, 07:35
Joined
Jan 14, 2017
Messages
18,221
As already mentioned, those tags are rich text. However only Long Text fields can use rich text.
How did you manage to get those tags into a short text field? Did you append the records from elsewhere?
You may find this article useful:

 

ThomasDirkse

New member
Local time
Today, 00:35
Joined
Apr 6, 2023
Messages
11
Many thanks for responding so quickly. I had to walk away from my desk to clear my head and now that I'm back I am NOT able to reproduce the problem I stated. My sincere apologies for this.

In the many attempts I made to fix my own problem, I made a number of changes. The field in question was at first a Long Text field and I switched it back and forth between Plain Text and Rich Text a few times. At some point, I changed the field to a Short Text field. I don't know how I ended up with the <div> tags but I cannot reproduce it anymore. I think the switching to Short Text must have eliminated the problem.

Anyway, I feel quite foolish that I cannot reproduce it and I apologize once more.

Thanks, Thomas.
BTW, Colin, thanks for the link to the article. I saved the link.
 

GPGeorge

Grover Park George
Local time
Yesterday, 23:35
Joined
Nov 25, 2004
Messages
1,867
Many thanks for responding so quickly. I had to walk away from my desk to clear my head and now that I'm back I am NOT able to reproduce the problem I stated. My sincere apologies for this.

In the many attempts I made to fix my own problem, I made a number of changes. The field in question was at first a Long Text field and I switched it back and forth between Plain Text and Rich Text a few times. At some point, I changed the field to a Short Text field. I don't know how I ended up with the <div> tags but I cannot reproduce it anymore. I think the switching to Short Text must have eliminated the problem.

Anyway, I feel quite foolish that I cannot reproduce it and I apologize once more.

Thanks, Thomas.
BTW, Colin, thanks for the link to the article. I saved the link.
What you did is called "trouble-shooting a problem" and other people ought to engage in that practice more frequently.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:35
Joined
Feb 28, 2001
Messages
27,186
I think that when you changed the field from LONG TEXT to SHORT TEXT while there were Rich Text codes in it, they became ordinary text and were retained as written. The question would then be whether if you changed the SHORT TEXT field to a LONG TEXT field and set the format appropriately, would the codes take effect to format the text strings? (I'm betting YES.)
 

ThomasDirkse

New member
Local time
Today, 00:35
Joined
Apr 6, 2023
Messages
11
I am really thankful for the incredibly quick and valuable responses I have had to my post. You pointed me in the right direction to unravel the mistake I had made. This is clearly the forum to watch and learn from.

I thought it might be valuable to document the consequences of making changes to the Text Format property on the Long Text field and the Text Box form field. There are a few combinations with some to me unexpected consequences.

I created a few Test Cases to explore the Text Format settings. I did this in two steps:
  1. Table and Datasheet
    In essence, this is just the table by itself. I use the datasheet to see the impact of my Text Format changes.

  2. Table and Form
    In this section, I put the Table and the Form together. The results are documented below.

Table and Datasheet
There are two levels of formatting with a Datasheet. In the MS Access top menu bar there are a number of formatting commands we typically associate with rich text, such as bold, colour, text size, etc. When you select these formatting commands, they will apply to the whole Datasheet. This is not the field-level formatting that we are looking at with the following test cases. We are looking at formatting capabilities specific to a Text Box field. This means that if we have a text with multiple sentences, Rich Text means we should be able to format the individual words and sentences.

TABLETABLE (cont.)OBSERVATIONS
Field TypeText Format property of table field
Short TextThis property does not exist for this field type.As expected, I can only enter plain text
Long TextPlain Text (which is the default)The only formatting commands I can access are those in the top menu bar which are datasheet-wide formatting commands as explained above this table.
Rich TextWhen I switch the Text Format property to Rich Text, MS Access gives me a warning that the text will be HTML-encoded.
When I select a portion of the text, a formatting bar pops up. Any command I choose will only apply to the selected portion of the text. The remaining text stays as is, as do all the other fields and records.
This is the expected behaviour.
Plain TextWhen I switch the Text Format property to Plain Text, MS Access gives me a warning that all formatting commands will be removed.
Indeed, in Datasheet view, all the previously formatted rich text is now converted back to plain text. There are no HTML commands visible.
Rich TextIf I now switch back to Rich Text again, the previously formatted rich text does not re-appear. Therefore, switching from Rich to Plain Text will indeed permanently remove all the formatting commands.


Table and Form
The setup is one Table with one field, either Short or Long Text, and one Form with one Text Box. Except for the first four Test Cases, the Text Box will be bound to the field in the table.
I could create a form with multiple Text Box fields, each illustrating one of the Test cases below. However, I am particularly interested in what happens when I change properties. This is what is displayed in the table below.
The Text Format property for the Text Box field can be found in Design View on the Property Sheet (Data tab) for the Text Box field.

TABLETABLE (cont.)FORMOBSERVATIONS
Field TypeText Format property of table fieldText Format property of entry field
------Plain TextAs expected, all text entered is just in plain text
Rich Text
(Unbound Text Box)
The moment I select all or a portion of the text, a Formatting bar pops up. Any of these commands will apply those formatting commands to the text selected.
Expected behaviour.
Plain Text
(Unbound Text Box)
Keeping the richly formatted text in the entry field, I will now switch the Text Format property to Plain Text.
All text is indeed converted to plain text but all the HTML-encoded tags are still there and visible.
Rich Text
(Unbound Text Box)
Without changing the content of the Text Box, I now switch the Text Format property back to Rich Text again.
All the HTML tags are re-applied and the text looks like it did before, i.e. richly formatted.
In all Test Cases below the Text Box is bound to the field in the Table
Short TextThis property does not exist for this field type.Can only be Plain TextThe Text Format property of the Text Box shows both Plain and Rich Text options but, the Rich Text option gives an error that it is not valid.
The text is plain text, as expected.
Long TextPlain TextPlain TextText entered into the Text Box is displayed, as expected, like plain text.
Rich TextWhen I try to switch the Text Format property of the Text Box, MS Access gives a warning that some of the data might not be displayed correctly but it accepts the new setting.
The Text Box accepts the rich formatting commands and displays the text correctly. However, the table is now not set for rich text and captures the data as plain text. All the HTML tags are converted to plain text.
If I look at the table with a Datasheet, I can see all the HTML tags in the richly formatted text.
Plain TextIf I now switch the Text Format back to Plain Text, you'll see all the previously entered data including all the HTML tags.
Long TextRich TextPlain TextPlain text is displayed and captured in the table as plain text. Expected behaviour.
However, the previously rich-formatted text is converted into plain text. It is a literal translation of all the HTML reserved symbols like '<' with '&lt' and '>' with '&gt'. So '<div>' becomes '&lt;div&gt;' Anyway, not exactly what you want.
Long TextRich TextRichAll plain text is displayed and captured as plain text.
All richly-formatted text that was entered before is shown as plain text with HTML tags.
All new text that is entered as richly-formatted text is displayed and captured correctly, as expected.

Conclusion
When using the Long Text field in an MS Access database, you have to exercise some care in setting the Text Format property of the table field as well as its bound Text Box. Especially when making changes to the Text Format property, you have to make the changes consistent across both the table and the form.
 

Users who are viewing this thread

Top Bottom