Today, I was preparing a demo db for a video I am hoping to make in the coming week and came across an odd issue with the Modern Web Browser.
Now, for full disclaimer, I haven’t done a deep dive into the matter. I simply identified the issue and implemented a workaround. So I don’t know if this is an issue with all cases, or just this particular site (I doubt it though).
I was trying to extract data from a site, so I created a variable representing all the matching span so I could then work with each one individually to perform other operations.
My basic coding approach was:
Set oSpans = oHTMLDoc.querySelectorAll("span")
For Each oSpan In oSpans
'Do some stuff
Next
'Do more stuff
For whatever reason, the code would run properly, get all the data I was after, but then Access would consistently and constantly crash at the end of the last iteration and would never get to ‘Do more stuff’.
I won’t tell you how much time I lost on this thinking it was something in my code, but it doesn’t appear to be the case as in my last attempt I decided to switch my approach to:
Set oSpans = oHTMLDoc.querySelectorAll("span")
For x = 0 To oSpans.length - 1
Set oSpan = oSpans(x)
'Do some stuff
Next
'Do more stuff
and everything works. Go figure?!
As I said, I haven’t fully explored this issue by any means (is it truly a bug?), but just wanted to share the workaround in case it can help someone else out there struggling with the For Each iteration in the Modern Web Browser control.