We help IT Professionals succeed at work.

How to display raw HTML code in a form.

Axter
Axter asked
on
I have a field in a table that contains some HTML code, and I want to display it on a form.

Anyone have any working method for this?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
for clarification, you want to display the RESULT (formatting, etc.) of the HTML right? not just the html (which is only text)?

there's no way to do this that i know of using native access controls. you would need to search out a third party control which is capable of displaying formatted html.

hopefully another expert knows of one you can use...

dovholuk
Richie_SimonettiIT Operations
CERTIFIED EXPERT

Commented:
If waht you need is unformatedHTML, use a textbox.
If you need formated: use webbrowser control.
Hope it helps.
AxterSenior Software Engineer

Author

Commented:
>>If you need formated: use webbrowser control.

I tried doing that, but it didn't work.
All I got was this control but I couldn't figure out how to put the HTML code in my field inside the webbrowser control.

Anyone have example code for this?
AxterSenior Software Engineer

Author

Commented:
>>or clarification, you want to display the RESULT
>>(formatting, etc.) of the HTML right?

That is correct.
Richie_SimonettiIT Operations
CERTIFIED EXPERT

Commented:
maybe:
webbrowser1.document.body.innerhtml = "string" ' of your field.
Richie_SimonettiIT Operations
CERTIFIED EXPERT

Commented:
Before doing that, you need to use navigate "about:blank" methos of component and put that code in document_complete event:

Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB1.Object) Then
    webbrowser1.document.body.innerhtml = "string" ' of your field.
   
End If
End Sub

This is a start only... we need to not hard code that way but just for show you one way to do
AxterSenior Software Engineer

Author

Commented:
This looks promising.

I'll test it out this evening, and get back to you.
AxterSenior Software Engineer

Author

Commented:
Richie_Simonetti,
What do you mean about the "about:blank"

I don't understand.
Can you give an example?
Richie_SimonettiIT Operations
CERTIFIED EXPERT

Commented:
If we need to write/change html text inside webbrowser, we would need at least a blank document to start from.
"about:blank" is a kind of constant that says to webbrowser to navigate to an empty document.
It is the same as change start page in IE properties dialog box. That option is the same as "Use blank page" or something like that (i have IE in spanish so i don't know the exact caption of the button).
AxterSenior Software Engineer

Author

Commented:
AxterSenior Software Engineer

Author

Commented:
Can you post an example?
IT Operations
CERTIFIED EXPERT
Commented:
On load event of form that contains Webbrowser control put this code:
' change the name of the object accordingly
webbrowser1.navigate "about:blank"
AxterSenior Software Engineer

Author

Commented:
Ok, that did the trick.

Private Sub Form_Current()
webbrowser1.Navigate "about:blank"
End Sub

Private Sub Form_Load()
webbrowser1.Navigate "about:blank"
End Sub

Private Sub webbrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is webbrowser1.Object) Then
   webbrowser1.Document.body.innerhtml = RawData ' of your field.
   webbrowser1.ClientToWindow 40, 30
End If
End Sub
Richie_SimonettiIT Operations
CERTIFIED EXPERT

Commented:
Cool!
Is it necessary to use both of them,Current an load?
or you are using that to clear webbrowser document content?
Thanks for the grade!
AxterSenior Software Engineer

Author

Commented:
I just tested it, and I see that I only need Current.

I couldn't use the Load because I needed the control to be updated when the formed moved to the next record.

I posted a new question asking how to keep the Web-browser control a certain size.

You wouldn't happen to know the answer?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.