Solved

Access VBA and I.E.

Posted on 2014-03-27
14
289 Views
Last Modified: 2014-04-10
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
0
Comment
Question by:rrhandle8
  • 8
  • 5
14 Comments
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
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
 

Author Comment

by:rrhandle8
Comment Utility
Wonderful!!!
0
 

Author Comment

by:rrhandle8
Comment Utility
Oops!  It keeps opening new browser windows.
0
 

Author Comment

by:rrhandle8
Comment Utility
Getting an "Application unknown error".
0
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
What exactly is the problem? I just tried it and it works as expected.
0
 

Author Comment

by:rrhandle8
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
What was the error message?
0
 

Author Comment

by:rrhandle8
Comment Utility
oIE.Refresh
0
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
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
 

Author Comment

by:rrhandle8
Comment Utility
I already posted that.
Getting an "Application unknown error".
It is losing track of the IE object.
0
 

Author Comment

by:rrhandle8
Comment Utility
If it helps, I am using Office 2010 on Windows 7
0
 
LVL 26

Accepted Solution

by:
MacroShadow earned 500 total points
Comment Utility
Strange. I can't replicate the error.
0
 

Author Closing Comment

by:rrhandle8
Comment Utility
The solution did not work on my PC.  I had to add some additional code.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 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

6 Experts available now in Live!

Get 1:1 Help Now