vendredi 2 mars 2018

MS Access VBA to get data from a web browser control's content

I have successfully used MS Access objects to open a browser window and read the data from that open window. However, I am now trying to read data from a web page that is open inside of a MS Access browser control object inside a form in Access, not in an external browser window.

Based on the code that worked when I was using objects, I tried the following to read data from the content showing inside the browser control in Access:

forms!frmOQWebWindow.webView.Document.getElementByID("lblSessionDate").innerText

and also

forms!frmOQWebWindow.webView.Object.Document.getElementByID("lblSessionDate").innerText

But both of those give me Run-time error '91': "Object variable or With block variable not set"

How can I read the value of an Element with the specified name ("lblSessionDate") when the web page is displayed inside a web browser control inside a MS Access form? I'm sure I'm missing something easy.

In case it helps, here is the code that works when I am using objects to read data from Elements on the same web page that throws an error when I try to read it from a browser control:

Dim weblink As String
Dim objIE As Object
Dim SessionDate As String

Set objIE = CreateObject("InternetExplorer.Application")
weblink = "http://www.somewebpage.com"
objIE.Navigate weblink

While objIE.Busy
    DoEvents
Wend

objIE.Visible = True  'make it visible; set this to false to hide the window

SessionDate = objIE.Document.getElementByID("lblSessionDate").innerText

Aucun commentaire:

Enregistrer un commentaire