Solved

Access VBA and I.E.

Posted on 2014-03-27
14
296 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 27

Expert Comment

by:MacroShadow
ID: 39960912
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
ID: 39961896
Wonderful!!!
0
 

Author Comment

by:rrhandle8
ID: 39961899
Oops!  It keeps opening new browser windows.
0
 

Author Comment

by:rrhandle8
ID: 39961910
Getting an "Application unknown error".
0
 
LVL 27

Expert Comment

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

Author Comment

by:rrhandle8
ID: 39992301
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 27

Expert Comment

by:MacroShadow
ID: 39992316
What was the error message?
0
 

Author Comment

by:rrhandle8
ID: 39992710
oIE.Refresh
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39992739
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
ID: 39993058
I already posted that.
Getting an "Application unknown error".
It is losing track of the IE object.
0
 

Author Comment

by:rrhandle8
ID: 39993064
If it helps, I am using Office 2010 on Windows 7
0
 
LVL 27

Accepted Solution

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

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Explanation of Access VBA code 2 36
Reset Active Directory Password via MS Access 9 56
Two list boxes - best structure 3 33
Acc 2010 pause execution 10 13
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

863 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

28 Experts available now in Live!

Get 1:1 Help Now