Access VBA and I.E.

I can open I.E. with the code below, bit I then want to refresh it from other forms.  Each form has a button that when clicked, creates a new preview.html page.




 Sub OpenBrowser()

    Public webBrowser1 As WebBrowser
    Set webBrowser1 = New WebBrowser
    Set webBrowser1 = CreateObject("InternetExplorer.Application")
    With webBrowser1
        .Navigate CurrentProject.Path & "\Preview.html"
        .Visible = True
    End With

End Sub
rrhandle8Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MacroShadowCommented:
Put this in a regular module:
Public oIE As Object

Open in new window


This will launch IE:
Sub OpenBrowser()

    Set oIE = CreateObject("InternetExplorer.Application")
    With oIE
        .Navigate CurrentProject.Path & "\Preview.html"
        .Visible = True
    End With

End Sub

Open in new window


This will refresh it, regardless of the form it's ran from:
oIE.Refresh

Open in new window

0
rrhandle8Author Commented:
Wonderful!!!
0
rrhandle8Author Commented:
Oops!  It keeps opening new browser windows.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

rrhandle8Author Commented:
Getting an "Application unknown error".
0
MacroShadowCommented:
What exactly is the problem? I just tried it and it works as expected.
0
rrhandle8Author Commented:
I had to add the following to avoid the error message.

Public Sub RefreshBrowser()

    Dim i As Long
    Dim SWs As New SHDocVw.ShellWindows
    
    For i = 0 To SWs.Count - 1
        'Debug.Print Now() & SWs(i).Document.Title
        'If InStr(1, SWs(i).Document.Title, "Preview") > 0 Then
            Debug.Print "Refresh"
            SWs(i).Refresh
            'Exit For
        'End If
    Next i
    
    Debug.Print Err.Description

End Sub

Open in new window

0
MacroShadowCommented:
What was the error message?
0
rrhandle8Author Commented:
oIE.Refresh
0
MacroShadowCommented:
I didn't ask on what line the error occurred, I asked what the error message was!

The reason I'm asking is because I couldn't duplicate the error, it worked fine for me.
0
rrhandle8Author Commented:
I already posted that.
Getting an "Application unknown error".
It is losing track of the IE object.
0
rrhandle8Author Commented:
If it helps, I am using Office 2010 on Windows 7
0
MacroShadowCommented:
Strange. I can't replicate the error.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrhandle8Author Commented:
The solution did not work on my PC.  I had to add some additional code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.