[RESOLVED] IE Object becomes "unknown" after Navigate called
Some code that used to work for me seems to have stopped working. I am using Windows Vista and Access 2007, and recently installed IE9, but am not positive that this was related to that installation... so I un-installed the IE9 update to return to IE8, but this problem continues.
My code is as follows (edited to show only relevant lines):
Dim WithEvents mobjIE As InternetExplorer
Dim strURL as string
Set mobjIE = New InternetExplorer
mobjIE.Visible = False
mobjIE.StatusBar = False
mobjIE.Silent = True
strURL = "http://download.finance.yahoo.com/d/quotes.csv?s=ABB,ABD,AFL&f=sl1d1t1dr1"
mobjIE.Navigate strURL
While mobjIE.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
Almost everything seems to work fine up until the last line... the only oddity is that the Explorer window IS visible. I see the correct information for the URL above come up in a new (and visible) IE window, and then my debugger break point on the last line kicks in. If I hover the mouse pointer over mobjIE.ReadyState as soon as the breakpoint is reached, I see:
Automation errorThe interface is unknown
and a while later (perhaps a minute or so) this changes to:
The remote server machine does not exist or is unavailable
Meanwhile, if I open a Watch window and enter mobjIE, it does not show any variables for this object.
Yet, if I set the break point one line earlier, and examine mobjIE BEFORE the navigate method is called, I see all information about the object as I would expect to. It seems as though the Navigate method is closing the IE object... yet the window with the results of the call remains open on my screen.
I have also:
- taken my ACCDB file to a client's computer (Win 7, IE8, Acc2007), and successfully run the same code without problems... so the trouble does seem to be a corruption on my machine.
- Run sfc, and other windows corruption-checker tools from Microsoft, but that did not solve anything.
- re-installed IE9, which works fine as a standalone application, and un-installed Access 2007, rebooted, and re-installed Access 2007.
- Copied all elements of my database into a new database file, with no change in the symptoms.
Any suggestions on next steps to try to resolve this? Thank you!
Last edited by GWFYarm; Mar 25th, 2011 at 07:01 PM.
Reason: Information from additional testing.
Re: IE Object becomes "unknown" after Navigate called
I think there is something going on with the IE install here. Automating IE is simply controlling what has historically IMO been one of the most flaky pieces of software that I've ever seen. My suggestion would be to move away from IE and move to something more stable like WinInet. I can provide you a sample wininet vba app when I get to work tomorrow that only uses the parts of the api that you would need if you are interested.
My experience with IE automation has always ended up in frustration and disappointment. It can be good for some quick one-time fix, but once you start to use it for something bigger and something that is put on multiple machines the problems start pouring in. I think you will be more pleased with the wininet api. Not only do you get more control over the connection, but it runs tons faster.
Re: IE Object becomes "unknown" after Navigate called
I would appreciate it very much if you could supply me with some sample code.
In particular, are there any "Tools/References" I would need to check off, or is WinInet used via a run-time binding? I have been starting to look through its documentation... but as with all such things it is MUCH easier to start from a stub of working code.
Re: IE Object becomes "unknown" after Navigate called
Here is a basic example provided in a word file.
Code:
Sub HttpTest()
Dim cls As New clsHttp
Dim doc As HTMLDocument
Dim elements As IHTMLElementCollection
Dim tbl As IHTMLTable
Dim summaryTable As IHTMLTable
'Basic web retrieval
cls.hOpen "GET", "http://download.finance.yahoo.com/d/quotes.csv?s=ABB,ABD,AFL&f=sl1d1t1dr1"
cls.Send
Do While cls.Busy
DoEvents
Loop
Debug.Print "The stocks are located in cls.Http.ResponseText."
'Example parsing the returned html
cls.hOpen "GET", "http://download.finance.yahoo.com"
cls.Send
Do While cls.Busy
DoEvents
Loop
Set doc = New HTMLDocument
doc.Body.innerHTML = cls.Http.ResponseText
Set elements = doc.getElementsByTagName("TABLE")
If elements.Length = 0 Then
Debug.Print "Unable to locate the market summary."
Else
For Each tbl In elements
'Tables aren't identified with an id or span, so let's find the ones with the text.
'Tables are usually nested, so it is usually necessary to find the very last one
'that has what you are looking for.
If InStr(1, Left(tbl.innerText, 30), "Market Summary", vbTextCompare) > 0 Then
Set summaryTable = tbl
End If
Next
Debug.Print "Today's market summary:"
Debug.Print summaryTable.innerText
End If
'Download a file
' cls.hOpen "GET", "http://ioquake3.org/files/models2/q3mdl-abe.zip"
' cls.Send
' Do While cls.Busy
' DoEvents
' Loop
' Debug.Print "The zip file is located in cls.Http.ResponseText."
End Sub
clsHttp is a very small class so it won't take much to wrap your head around. Its usage is very similar to ie. You could easily add a navigate method to the class that would wrap the open/send methods. You will see that I added some transfer speed calculations to debug.print. These could easily be spit out through an event to display or just ignored.
Re: IE Object becomes "unknown" after Navigate called
Originally Posted by GWFYarm
In particular, are there any "Tools/References" I would need to check off, or is WinInet used via a run-time binding?
You could remove the references for late binding, but then you would not be able to use the async mode where. The code would block until the download was complete, freezing your UI.
WinHTTP is now an operating-system component of the following operating systems: (source)
* Windows 2000, Service Pack 3 and later (except Datacenter Server)
* Windows XP with Service Pack 1 (SP1) and later
* Windows Server 2003 with Service Pack 1 (SP1) and later
One day in the far off future, MS could decide to only package 5.2 or later and that would break any early binding code until the reference was fixed and the code reviewed to work with the new version. This is something you have to consider.
Re: IE Object becomes "unknown" after Navigate called
Thank you for the help!
Your zip file does contain a word document, but the document is empty when I open it (Word 2002).
Not being able to see the contents of HTTPTest, I am not sure if I need to check "Microsoft WinHTTP Services, version 5.1" under Tools/References in order to use the approach you advocate. When I do try checking this, I receive an error message saying "Error in loading DLL".
Re: IE Object becomes "unknown" after Navigate called
Alt+F11 opens the vba code editor in word just like in ms access. The references in the word document are just like what would be required in access. You only have to copy the clshttp file to access.
Re: IE Object becomes "unknown" after Navigate called
Silly me. It never occurred to me you had VBA code behind word. Your instructions worked.
I have managed to find out how to correct my error loading WinHTTP.dll (turn off UAC under Vista, then re-register the dll, then turn UAC back on). This did not fix my original problem though (I was hoping it might), so I will continue switching over to WinHTTP.
Many thanks for the assitance!
Last edited by GWFYarm; Mar 28th, 2011 at 12:51 PM.
Reason: Additional results
Re: IE Object becomes "unknown" after Navigate called
It appears the WinHTTP registration error is something that has happened to a number of people under Vista and Windows 7. It seems fixed now.
I have successfully transitioned all of my code to WinHTTP, and it works quite nicely now. And, as you indicated it would be, it is considerably faster too.
Thank you very, very much for all your assistance!
Last edited by GWFYarm; Mar 29th, 2011 at 05:43 AM.