Solved

Display HTML formatted data in Access form

Posted on 2012-12-21
7
3,059 Views
Last Modified: 2012-12-22
I am creating a form which pulls its data from a linked MS Sql server database.  In that database is a column which stores the data as HTML.  I join that table to a couple of others in a query which is the record source for my form.  The column in question is a text format – that comes from the sQL server database.
 
I would like for this data to display correctly, although it would be OK if the HTML formatting were lost.  When I display that column in my form, all the HTML tags show.  Changing the format to RTF does not correct this, apparently that only works if the underlying field is Memo format.  

I’ve searched here and other similar sites and found some hints that I could use the web browser control but not any clear instruction on how to do it.  In my experiments I haven’t been able to figure out how to make the data in each row show up in the web browser control.  (In fact, I’ve been using the control ‘Hyperlink’, not finding a control actually called ‘Web Browser’… surely they are the same, right??)  

Anyone able to help me with this please? As an alternative I would be ok with losing the HTML formatting in the query if there is some way to do that - maybe a calculated column that pulls the text data from the HMTL?

Thanks -
0
Comment
Question by:susanhibbard
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38715133
If you're using Access 2007 or later, you can use the PlainText() function to remove the HTML tags.
=PlainText(NameOfFieldWithHTMLstring)
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38715137
You can also add an unbound textbox to your form and change it's TextFormat property to Rich Text.  Then in the OnCurrent event of your form add something like:
Me.NameOfRichTextbox = [NameOfFieldWithHTMLstring]

This way you would see the text displayed almost as you would in a browser (whatever RTF is able to render properly since it cannot handle all HTML tags).
0
 

Author Comment

by:susanhibbard
ID: 38715579
I tried both of these solutions and both are still displaying the HTML tags.   Access version is 2010.

I am not experienced in HTML so maybe there is something more going on with this field that I don't understand, but I do know that when I place it in a Crystal report and format it as HTML they display properly...

Here is a sample of the data in this field:

"<style type=""text/css"">
  body {font-size:8pt;font-family='MS Sans Serif',sans-serif;color:000000 ;background-color:FFFFFF;}
  td {font-size:8pt;font-family='MS Sans Serif',sans-serif;color:000000 ;background-color:FFFFFF;}
</style>

<html><body leftmargin=""0"" topmargin=""0"">

<ul>
<big>• </big><b>1- 6 in (H)  x 2 in (W)  Dimensional Sign(s)</b> made from <b>Coro - 10 mil White 48 x 96</b> stock material&nbsp;<br>

</ul>

</body></html>"


On further investigation, when I look at the table design in Access (read-only, of course) it shows as a memo data type, which I understood should display correctly using RTF formatting in access:
Screen shot of table design
So I am even further confused why it does not display the HTML since as I understand it Access should render the HTML in these circumstances.

Any further suggestion on this solution?

And if anyone has the answer to my initial question about using the Web browser control that would be appreciated as well...

Thanks,
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 38715633
I just tried what you gave and it does render the HTML tags correctly.  The problem is that you also have CSS style tags.  As I said, RTF can only render certain types of tags.

For the Web Browser control, you have to select ActiveX Controls on your ribbon (where the other controls are).  The one you need is called Microsoft Web Browser.  Add that to your form and give it a name (e.g. ctlWebBrowser).  Then add this code to your OnLoad event to "initialize" the browser.

Private Sub Form_Load()
    
    'Needed to "initialize the webbrowser control,
    Me.ctlWebBrowser.Navigate "about:blank"
    Do While ctlWebBrowser.ReadyState <> 4
        DoEvents
    Loop
End Sub

Open in new window

Then in your OnCurrent event, add something like this:
     
   Me.ctlWebBrowser.Document.body.innerHTML = [NameOfFieldWithHTMLstring]
0
 

Author Closing Comment

by:susanhibbard
ID: 38715661
That works!  thanks for your help!
0
 

Author Comment

by:susanhibbard
ID: 38715673
Alas, this is a continuous form and the html data is only appearing on the current row...

I don't suppose there is any solution for that problem?  

so close and yet so far away!
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38716506
Unfortunately this will not work in a continuous form.  How about adding an unbound textbox set to Rich Text and use this expression in its ControlSource:
=Mid([FieldName],IIf(InStr([FieldName],"<HTML>")=0,1,InStr([FieldName],"<HTML>")))

The above looks for the <HTML> tag in your field and ignores the text before it.  That way the rest can render properly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now