I am trying to get data about some football players from the website in order to fill out a personal database. I have included all the code below. This first section is a looper that calls a second function to populate the database. I ran this code in MSAccess to populate the database last summer, and it worked great.
Now I have only a few commands to fill before the program crashes in
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
I searched countless websites about this error and tried to change this code by adding a subfunction to wait for a few seconds or other workarounds. None of them solves the problem. I also tried running this on multiple computers.
The first computer did this through 3 commands (or three calls to the 2nd function). The second slow computer does this through 5 commands. Both end up hanging. Internet Explorer 10 is installed on the first computer, and IE8 is installed on the second.
Sub Parse_NFL_RawSalaries() Status ("Importing NFL Salary Information.") Dim mydb As Database Dim teamdata As DAO.Recordset Dim i As Integer Dim j As Double Set mydb = CurrentDb() Set teamdata = mydb.OpenRecordset("TEAM") i = 1 With teamdata Do Until .EOF Call Parse_Team_RawSalaries(teamdata![RotoworldTeam]) .MoveNext i = i + 1 j = i / 32 Status("Importing NFL Salary Information. " & Str(Round(j * 100, 0)) & "% done") Loop End With teamdata.Close ' reset variables Set teamdata = Nothing Set mydb = Nothing Status ("") 'resets the status bar End Sub
Second function:
Function Parse_Team_RawSalaries(Team As String) Dim mydb As Database Dim rst As DAO.Recordset Dim IE As InternetExplorer Dim HTMLdoc As HTMLDocument Dim TABLEelements As IHTMLElementCollection Dim TRelements As IHTMLElementCollection Dim TDelements As IHTMLElementCollection Dim TABLEelement As Object Dim TRelement As Object Dim TDelement As HTMLTableCell Dim c As Long ' open the table Set mydb = CurrentDb() Set rst = mydb.OpenRecordset("TempSalary") Set IE = CreateObject("InternetExplorer.Application") IE.Visible = False IE.navigate "http://www.rotoworld.com/teams/contracts/nfl/" & Team While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend Set HTMLdoc = IE.Document Set TABLEelements = HTMLdoc.getElementsByTagName("Table") For Each TABLEelement In TABLEelements If TABLEelement.id = "cp1_tblContracts" Then Set TRelements = TABLEelement.getElementsByTagName("TR") For Each TRelement In TRelements If TRelement.className <> "columnnames" Then rst.AddNew rst![Team] = Team c = 0 Set TDelements = TRelement.getElementsByTagName("TD") For Each TDelement In TDelements Select Case c Case 0 rst![Player] = Trim(TDelement.innerText) Case 1 rst![position] = Trim(TDelement.innerText) Case 2 rst![ContractTerms] = Trim(TDelement.innerText) End Select c = c + 1 Next TDelement rst.Update End If Next TRelement End If Next TABLEelement ' reset variables rst.Close Set rst = Nothing Set mydb = Nothing IE.Quit End Function
internet-explorer vba access-vba internet-explorer-8 internet-explorer-10
Doubledown
source share