Display HTML code in Web Browser (2 Viewers)

philbullock1223

Registered User.
Local time
Today, 03:24
Joined
Dec 31, 2011
Messages
55
I am trying to display HTML code inside a Access Web Browser Control. I have been successful in making an html document and setting the control source to the file in the Web Browser Control. This isn't an ideal solution.

I have been searching how to solve this for a while. Someone said this would work:

Code:
Set Web = Wb.Object
Web.Navigate "about/blank"
Web.Document.Open "text/html"
Web.Document.Write "hello world<br>"
Web.Document.Close

When I run this in Wb_BeforeNavigate2, my code locks up (feels like it's in a loop and I need to break). The name of my Web Browser Control is "wb." I am using Access 2013. Microsoft Internet Controls are referenced.

Any help would be absolutely appreciated.
 

static

Registered User.
Local time
Today, 08:24
Joined
Nov 2, 2015
Messages
823
The browser control needs a time delay to initialise.

Code:
Private Sub Form_Load()
    Web.Navigate "about:blank"
    Me.TimerInterval = 300
End Sub

Private Sub Form_Timer()
    Me.TimerInterval = 0
    Web.Document.write "<div style='font-family:arial;font-size:20pt;color:blue;'>hello world</div>"
End Sub
 

philbullock1223

Registered User.
Local time
Today, 03:24
Joined
Dec 31, 2011
Messages
55
Static, thank you so much for the reply.

I am getting the error "Method or Data Member Not Found" on the .Navigate. I have tried to fix this issue, but all of the resources I have read indicate that I must turn on Microsoft Internet Controls in the references. I have confirmed Microsoft Internet Controls are checked on. I also tried to deactivate then reactivate it with no luck.

Any reason this might be happening?

Thanks again!
 
Last edited:

static

Registered User.
Local time
Today, 08:24
Joined
Nov 2, 2015
Messages
823
I used Web but your control is wb so you still need.

Set Web = Wb.Object

Otherwise, all I can suggest is to delete the control and re add it. That should set up any references.

Go to code view, press F2, select ShDocVw from the drop down and webbrowser under classes. You should see navigate / navigate2 in the members list.
 

philbullock1223

Registered User.
Local time
Today, 03:24
Joined
Dec 31, 2011
Messages
55
I changed the code so I don't need the Set Web = Wb.Object. With that said, I get the same error.

I am able to find Navigate under F2->ShDocVw->webbrowser under classes. Can you tell me how to "delete" a control. I can unclick the checkbox and reclick it, which I have done a few times with no luck.

I also created the fresh database attached that has just this basic issue.

Thanks again for all your help.

My code is currently:

Code:
Private Sub Form_Load()
    Wb.Navigate "about:blank"
    Me.TimerInterval = 300
End Sub

Private Sub Form_Timer()
    Me.TimerInterval = 0
    Wb.Document.Write "<div style='font-family:arial;font-size:20pt;color:blue;'>hello world</div>"
End Sub
 

Attachments

  • Test.accdb
    584 KB · Views: 250

philbullock1223

Registered User.
Local time
Today, 03:24
Joined
Dec 31, 2011
Messages
55
I got it to work with a few tweaks! Still not sure the exact reasoning, but we are all good now!

Thanks again Static. You were a HUGE HELP! :D

Code:
Private Sub Form_Load()

    Set webControl = Me.Wb.Object
    With webControl
        .Navigate "about:blank"
    End With
    Me.TimerInterval = 300
    
End Sub

Private Sub Form_Timer()

    Set webControl = Me.Wb.Object
    Me.TimerInterval = 0
    With webControl
        .Document.Write "<div style='font-family:arial;font-size:20pt;color:blue;'>hello world</div>"
    End With
    
End Sub
 

philbullock1223

Registered User.
Local time
Today, 03:24
Joined
Dec 31, 2011
Messages
55
One last question and I think I will have everything I need.

If I try to update the HTML code with the .Document.Write strHTML command, I get a duplicate of the code (i.e. it will say Hello World twice).

What command can I use to clear out the code so I don't get a repeat?

:banghead:

Phil
 

JHB

Have been here a while
Local time
Today, 09:24
Joined
Jun 17, 2012
Messages
7,732
I would not trust in a timer, but instead wait until the web control is ready.

Code:
  Do
     DoEvents
  Loop Until webControl.ReadyState = READYSTATE_COMPLETE 'READYSTATE_COMPLETE=4
form hours.
 

Users who are viewing this thread

Top Bottom