Some preliminary information.
This application was written by another individual that hasn't been with the company for several years.
I have dabbled with VBA in Excel, lots of differences and function that I am not familiar with in Access.
There is an Excel application that is used by many other departments that uses 3 of the 4 Global Constants used for URLs where this data is found.
Several months ago, the locations were moved to different servers/URLs. Both the Excel application, and this Access application ceased functioning. I reached out to the owner of the Excel app and he sent me an updated copy of the sheet. After poking through the Excel code, I found the paths. I looked at the Access code and found the same information but with an additional URL.
I updated the Access to match the Excel paths and it looked like things were good. However, the Access application will not always run. I went into the code, rem’d the On Error statement to see where the code was faulting. It seems that a RecordSet is already at .EOF when it encounters a .MoveFirst command. The fact that this application will run at times and have no problem while erroring out other times makes me think it could be a timing issue with the data or network due to a plethora of “Sleep” and “Do Event” commands peppered through the code or another reason that I can't put a finger on.
With rs
.MoveFirst
Do Until .EOF
In the part of the code below referencing WebBrowser0 is where I think my issue is. I don’t think the data is being picked up.
Italic text is modified code to not show actual info but I hope I’m explaining things well enough to not be totally confusing.
This first bit of code is where I think the issue is.
Location-path is the server page url
ToolString is the string with all the separate entities concatenated together
Code:
With Forms!Main.Form!ToolStatus.Form.WebBrowser0
.navigate Location-path & ToolString
While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
Do While .ReadyState <> 4: DoEvents: Loop
End With
It then starts through 4 different With statements that relate to equipment that is grouped by what it is used for.
If [Forms]![Main].[Form].[cboArea] = "ToolsA" Then
Sleep (1000)
With Forms!Main.Form!ToolStatus.Form.WebBrowser1
.navigate ToolsA1
Do While .ReadyState <> 4: DoEvents: Loop
End With
Sleep (1000)
With Forms!Main.Form!ToolStatus.Form.WebBrowser2
.navigate ToolsA2
Do While .ReadyState <> 4: DoEvents: Loop
End With
Sleep (1000)
With Forms!Main.Form!ToolStatus.Form.WebBrowser3
.navigate ToolsA3
Do While .ReadyState <> 4: DoEvents: Loop
End With
Sleep (1000)
With Forms!Main.Form!ToolStatus.Form.WebBrowser4
.navigate ToolsA4
Do While .ReadyState <> 4: DoEvents: Loop
End With
Else ToolsE
Set HTMLDoc = Forms!Main.Form!ToolStatus.Form.WebBrowser0.Docume nt
The next line of code is where things don’t happen.
Set Tables = HTMLDoc.getElementsByTagName("TABLE")
I put” If Tables.Length = 0 Then Stop” in as a troubleshooting step and yeah, the code would stop here if this line was not there.
Thank you in advance for any input.