Automation error with Set IE = CreateObject("InternetExplorer.Application")

I'm running code in MS Access 360 on a Windows 7 machine to do website captures... The code was developed and originally run on an XP machine using IE 8.

The new machine is Windows 7 and uses IE 11.

When the code gets to the line:

 Set IE = CreateObject("InternetExplorer.Application")

I get the following error message:

Automation error
Unspecified error

In the MS Access references, I have selected Microsoft Internet Controls.  It is pointing at ieframe.dll in the SysWOW64 folder
I'm sure this code worked at one point on this machine.  I have no idea what changed.
pcalabriaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

John TsioumprisSoftware & Systems EngineerCommented:
maybe unregister and reregister the .dll to see if somethimg else is going on
0
NorieAnalyst Assistant Commented:
You shouldn't need a reference if you are using CreateObject.
0
pcalabriaAuthor Commented:
I just have it dimensioned as a object.. is that ok?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

NorieAnalyst Assistant Commented:
That should be fine.

Try removing the reference to Internet Controls and running the code again.

If that doesn't work try setting the reference again and rather than using CreateObject try this.
Set IE = New InternetExplorer

Open in new window

0
pcalabriaAuthor Commented:
I'll give those things a try.. but keep in mind.. it used to work on the same machine.
0
pcalabriaAuthor Commented:
@John Register then re-register did not work.. if what you mean is check and then uncheck.

I unchecked...closed access.. then opened and rechecked.. no help.
0
Gustav BrockCIOCommented:
First, go to menu Debug and compile the project. If any error, correct and repeat until success.
Then save the module. and close the VB editor.

Now, go to menu (Database) Tools, and click (at left) Compact and Repair Database.

When done, try to run your code.
0
John TsioumprisSoftware & Systems EngineerCommented:
unregister/register  means
C:\Windows\SysWOW64\regsvr32 /u ieframe.dll
C:\Windows\SysWOW64\regsvr32  ieframe.dll

Open in new window

If there is an issue with the .dll it will bomb out..
0
pcalabriaAuthor Commented:
I've tried all of the suggestions offered but still get the same error.
I do have NEW information however.

The code always works correctly when the machine is rebooted.
The following line executes without error.

Set IE = CreateObject("InternetExplorer.Application")

The application is encountering an error and when the code is restarted, a second time, without rebooting the machine, the line above fails.
Perhaps the first object still exists???

Any ideas?
0
Gustav BrockCIOCommented:
Yes, that typically indicates that you don't get the object closed decently when your code has finished using it.
0
pcalabriaAuthor Commented:
I'm still stuck... I tried adding the code:

 On Error Resume Next
 IE.Close
 Set IE = Nothing
 
 On Error GoTo Error_Routine

before Set IE = CreateObject("InternetExplorer.Application") but I get the same error.  The routine ran about 80 times before it failed.  Once it failed, I could not get it to start again without rebooting.

Any ideas would be appreciated!
0
Gustav BrockCIOCommented:
You must also first kill any objects opened after the IE object was opened.

But you have the code. We have nothing.
0
pcalabriaAuthor Commented:
I'm not sure what you mean by kill...
Use on error the ie.close?
Isn't that what I'm effectively doing?
0
NorieAnalyst Assistant Commented:
There is no Close method for Internet Explorer, to close an instance of Internet Explorer you use Quit.
IE.Quit

Open in new window

0
Gustav BrockCIOCommented:
As I wrote:

But you have the code. We have nothing.

That leave's with guessing only.
0
pcalabriaAuthor Commented:
So my condo now looks like this:

On error resume next
IE.quit
Set IE=nothing

On error goto ErrorRoutine
Set IE=createobject("internetexplorer")

My hope is that if the operation fails this code will prevent the reported error without rebooting.

Does this seem correct!

Thanks
0
NorieAnalyst Assistant Commented:
Can you post the whole code?
0
pcalabriaAuthor Commented:
Public Sub ReadURLandSaveNew2(strURLtext As String, bolSuccess As Boolean, strWebsite As String, Optional strLocalFile As String, Optional SearchNumber As String, Optional bolAbort As Boolean)

'This routine was written with the help of Jim Detman of Experts Exchange
'The routine addresses allows us to capture data from the pccomponents website which requires that we first login
'To use the routine you must first go the the pccomponents website and log in using IE and our company password
'This routine allows us to accomplish the log in using IE
'The routine is only being used for the pccomponents website
'for some unknown reason at this time, the routine does not work with the other website we use that does not require a log in
'The original routing (created with help from Gustav Brock will continue to be used with websites which do not require that we first sign in (ReadURLandSaveNew)


    Dim i As Long
    Dim URL As String    
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
    Dim strURL As String
   
    On Error GoTo Error_Routine
   
    strURLtext = ""
    bolAbort = False
    bolSuccess = False
   
    DoEvents: If bSilentMode = False Then Forms!frmCaptureWorldInventory.txtStatus = "Entered ReadURLandSaveNew2 Subprogram"


    If strWebsite = "pccomponents" Then
        'if we are making a capture with pcComponents set the URL and Local file name to that of the pcComponents URL and file name
        strURL = "http://www.pccomponents.com/results.htm?r=1&t=f&src=&so=&lgc=equals&pn1=" & SearchNumber & "&slgc1=equals&QTY_MIN_FLT=0&fQTY_MIN_FLT=0"
        strLocalFile = stCaptureFilePath & "CaptureURLnet.htm"
    End If

    If strWebsite = "pcc" Then
        strURL = "http://www.pcc.com/avail?part=" & SearchNumber
        strLocalFile = stCaptureFilePath & "CaptureURLfc.htm"
    End If
   
'this code no longer works due to a change in the website code
    If strWebsite = "ConvertCurrency" Then
    'the searchnubmer field is used to parse into the URL
        strURL = "http://xe.com"
        strLocalFile = stCaptureFilePath & "CaptureCurrency.htm"
    End If


 On Error Resume Next
 IE.Quit
 Set IE = Nothing
 
 On Error GoTo Error_Routine
 
 
    'Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
 
    'Set IE.Visible = True to make IE visible, or False for IE to run in the background
    IE.Visible = False
 
    'Define URL

     'URL = "https://www.pccomponents.com"
    URL = strURL
   
    'Navigate to URL
    IE.Navigate URL
 
    ' Statusbar let's user know website is loading
    ' Application.StatusBar = URL & amp; " is loading. Please wait..."
 
    ' Wait while IE loading...
    'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
    Do While IE.ReadyState = 4: DoEvents: Loop   'Do While
    Do Until IE.ReadyState = 4: DoEvents: Loop   'Do Until
 
    'Webpage Loaded
    ' Application.StatusBar = URL & amp; " Loaded"
   
    'Save page
    strURLtext = IE.Document.DocumentElement.innerHTML
   
   
    'Verify we are still logged in when capturing from pcComponents
    If InStr(strLocalFile, "CaptureURLnet") > 0 And InStr(strURLtext, "demo mode") > 0 Then
        strErrorMessage = "Please sign-in to pcComponents using INTERNET EXPLORER and then try again"
        Forms!frmCaptureWorldInventory!txtStopMessage = strErrorMessage
        Forms!frmCaptureWorldInventory!txtOnOff = "Stopped"
        DoEvents
        MsgBox "You are not signed into pcComponents" & vbCrLf & vbCrLf & "Use the ""Capture Codes"" button to see the captured page (""WI Text"" or ""WI HTML"")"
        bolAbort = True
        GoTo Error_Routine
    End If



bolSuccess = True
DoEvents: If bSilentMode = False Then Forms!frmCaptureWorldInventory.txtStatus = "Exiting ReadURLandSaveNew2 Sub (no Errors) " & strLocalFile

Exit Sub

Error_Routine:

DoEvents: Forms!frmCaptureWorldInventory.txtStatus = "Error in ReadURLandSaveNew2 Sub: " & strErrorMessage
   
Exit Sub
   
   
    'Unload IE
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
   
    'MsgBox "done"
   
    End Sub
0
pcalabriaAuthor Commented:
The above routine is called by executing this line of code:

Call ReadURLandSaveNew2(strText, bolURLSuccess, "pccomponents", strLocalFile, StripNumber(strPN))

The problem is that while this code may work for hundreds of different stPN's, sometimes it fails and when it fails I need to reboot the machine to clear the error.

My goal is to figure out why the code is failing, and prevent the failure.
0
NorieAnalyst Assistant Commented:
Why are you handling, i.e. closing IE, when there is an error?

All the error routine in that code does is put a message in a textbox on a form, it does nothing with IE which means you could have 'ghost' instances floating about and that could be the root of the problem.
0
pcalabriaAuthor Commented:
So what should my error routine do??

Ie.quit
Set IE=nothing

The real question is why is there an error in the first place. I don't expect any.
0
NorieAnalyst Assistant Commented:
What you could is remove/comment out the  On Error.... stuff, that could be hiding errors.
0
pcalabriaAuthor Commented:
Only place I use on error next is where I want to make sure the object is already closed before opening.. that's all new code.. if singles stepped through it
0
Gustav BrockCIOCommented:
First, this won't work - or rather, it will always fail - as IE at this point always is Nothing:

On Error Resume Next
IE.Quit

Open in new window

Then, here you only could quit IE in case of an error, but - before that - you exit the sub:

    bolSuccess = True

Exit Sub

Error_Routine:

    Exit Sub
    
    'Unload IE
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
    
End Sub

Open in new window

Finally, if the two other objects were used (have you left out some code?), they must be killed in reverse order:

    Set IE = CreateObject("InternetExplorer.Application")
    Set objCollection = ' something
    Set objElement = ' something

    ' Do stuff.

    Set objElement = Nothing
    Set objCollection = Nothing
    Set IE = Nothing

Open in new window

0
pcalabriaAuthor Commented:
Please excuse the typos in the above message. I've been responding from my cell phone.

I was trying to say that the "on error next" statement, and statements following it to quit IE and set the object to nothing, were only added as a troubleshooting test in attempt to fixed the problem.

The bottom line is that the routine that captures the text returned by the URL occasionally fails, and when it fails the machine must be rebooted.
0
NorieAnalyst Assistant Commented:
How does it fail?

Is the URL not returning what's expected?

P.S. Did you arrive at this code after asking a question here previously?

If so it might help to post a link to the original question.
0
pcalabriaAuthor Commented:
I am trying to figure out what makes the code fail but without success.

I trapped the last error and found nothing eventful.  It was a good url and a good page came up when the url was posted.

I did notice that it is adding an instance of IE every time the loop runs.. perhaps it's running out of memory?

The ReadURLandSAveNew routine is called each time I capture a page.  I thought I was setting the objects properly each time I exit the loop but apparently I'm missing something?

Do I need ie.quit in the exit loop?
0
Gustav BrockCIOCommented:
I did notice that it is adding an instance of IE every time the loop runs.. perhaps it's running out of memory?

No, but it would eventually.

What you need is to not/never exit the sub before you have closed ID and then set it to Nothing.
0
pcalabriaAuthor Commented:
The entire code is as entered above, except of course the line which calls the sub (which I also entered in a separate message).

Another EE member provided me with this code, which I may have modified for my purposes.  The original code included dim statements for objElement and objCollection... I don't know why these references were including.  I did add code to set these objects to nothing when I started to have problems... but I never had code to SET the objects to anything.

It does add separate instances of IE in the task manager... I've modified my code to set IE = nothing when an error occurs.;.. should I be using ie.quit first?
0
Gustav BrockCIOCommented:
Yes:
What you need is to not/never exit the sub before you have closed IE and then set it to Nothing.
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
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.