The Access Web Browser Control is not a Web Browser Object, but does contain one. To access the internal workings of the control with VBA code, it is most convenient to dimension and use variables as follows, where the name of the control is “MyWebBrowserControl”:
DIM MyBrowser as WebBrowser
DIM MyHTMLdoc as HTMLDocument
…
Private Sub Form_Load()
…
DoEvents ‘ let the browser object startup process complete
Set MyBrowser = MyWebBrowserControl.Object
Set MyHTMLdoc = MyBrowser.Document
…
End Sub
…
Setup
You need to add the following two references in the [Tools | References] section of the VBA IDE:
· Microsoft HTML Object Library
· Microsoft Internet Controls
Using the Control to display an HTML string
If you just want to use the browser control to display some HTML text stored in a database field named “NoteHTML” you can use something like the following code:
Private Sub Form_Current()
…
MyHTMLdoc.body.innerHTML = Me.Recordset!NoteHTML
…
End Sub
Other use cases
- You can programmatically control the browser object by filling in and reading fields from a known web page. See the following for ideas:
https://www.utteraccess.com/wiki/Access_and_the_web_HTML_Object_Library - You can programmatically display an HTML file stored on your PC.
- You can create a Web Browser form that gives controlled access to the web and/or provides added features such as storing search terms and/or page history in a database table for further and extended processing.
- You can “screen scrape” data from known web pages to populate your database. See the following for ideas and sample code:
http://automatetheweb.net/vba-getelementsbytagname-method/
Tips
If you don’t use the Wizard to define the web browser control, then be sure to specify a valid address for the Control Source so that the object will initialize correctly.
If you want a blank control at startup you can specify Control Source = “about:blank”
Once the setup above is done you can refer to the actual browser object properties and methods via the MyBrowser variable.
Using the MyHTMLdoc variable you can refer to named tags (data fields, control fields, etc.) within the target Web Page.
Learn to use the developer dialog (F12) of the web browser of your choice in order to determine the field names of interest for screen scraping, etc.
Documentation from Microsoft:
https://docs.microsoft.com/en-us/office/vba/api/access.webbrowsercontrol