Link to home
Start Free TrialLog in
Avatar of seanlhall
seanlhallFlag for United States of America

asked on

How can I display HTLM from a string in a WebBrowser Control?

I have a form with a Active X Webbrowser control. I want to display HTML from a string. I know how to display a web page and open a HTML file with out a problem. I found this code and it appears it is what I am looking for.  The problem is I get an Error 'Run time Error 91 Object variable or With block variable not set. I have referenced MS HTML Object Library and MS Internet Controls. What am I missing?


    Dim HTML As String
        HTML = "<HTML>"
            HTML = HTML & "<p> Preview my HTML string </p>"
        HTML = HTML & "</HTML>"
     
    Dim obj As HTMLDocument
       Set obj = WebBrowserControlName.Document
       obj.body.innerHTML = HTML
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As strange as it seems, ...from my experience, I have never seem anything that will easily display an HTML "string" in a webbrowser control.

It's as if the web browser control can only read data from a (disk) "file".
    c:\YourFolder\YourFile.HTML

So you could use code to save the string out to a temp file, then point the webbrowser at that...

The good news is that Access 2007-2010 format databases (.accdb format), can display Formatted HTML.
You must create a Memo Field and set the Text Format property to "Rich Text"

JeffCoachman
Jeff, you actually can create it from a string.  I have done this a couple of times.  The error the OP is getting in this case is because the WebBrowser's Document property returns Nothing if the control isn't first "initialized" when the form loads.  This is done by having it navigate to a url or a blank page.

/Ron G.
Avatar of seanlhall

ASKER

It works thanks.
...so I learned something new as well...
;-)

Jeff