Blog Post
Access Releases 7 Issue Fixes in Version 2311 (Released November 25th, 2023)
I have found a workaround to the ControlSource issue.
This is a kludge which uses a function at runtime to open the form containing the web browser control in design mode and set it's ControlSource to a local file path determined at runtime. I would not normally advocate such a technique.
When you specify a local file for the ControlSource on the property sheet in design mode, Access automatically prepends the specified path with https:/msaccess/ The modified path is shown on the property sheet. I have found that this also occurs if you specify the ControlSource using VBA in design mode at runtime, so you should not prepend the local file path with https:/msaccess/ as you would for the Navigate method. If you do, then when you open the form it tries to open the local file as a website and opens a browser page with an error message.
Here is a function which sets the ControlSource at runtime:
Function WebBrowserSetControlSource()
' set ControlSource in design mode
Dim strForm As String
Dim strWebBrowser As String
Dim strBlankHTM As String
Dim frm As Form
Dim ctl As Control
strForm = "frmInvoiceWeb"
strWebBrowser = "WebBrowser"
strBlankHTM = WebBrowserBlankHTM()
DoCmd.OpenForm strForm, acDesign, , , , acHidden
Set frm = Forms(strForm)
Set ctl = frm.Controls(strWebBrowser)
If InStr(ctl.ControlSource, strBlankHTM) = 0 Then
'ctl.ControlSource = "=""https:/msaccess/" & strBlankHTM & """"
ctl.ControlSource = "=""" & strBlankHTM & """" 'Note: Do NOT specify https:/msaccess/ when setting ControlSource
DoCmd.Close acForm, strForm, acSaveYes
Else
DoCmd.Close acForm, strForm, acSaveNo
End If
End Function
Note: The ControlSource is only set if it is not already pointing to the specified local file. This avoids multiple design changes which might cause database bloat.
Here is the supporting function which creates Blank.htm file in the folder containing the database. This is a good choice for the runtime folder because the folder must exist for the database to exist and the user must have permission to write to the folder to be able to run the database.
Function WebBrowserBlankHTM() As String
' create/return Blank.htm in current database folder
Dim strFilename As String
Dim iFile As Integer
strFilename = CurrentDb.Name
strFilename = Left(strFilename, InStrRev(strFilename, "\")) & "Blank.htm"
' create Blank.htm
If Dir(strFilename) = "" Then
iFile = FreeFile()
Open strFilename For Binary As iFile
Put iFile, , "<!DOCTYPE html><html><head><title>Blank</title></head><body></body></html>"
Close iFile
End If
WebBrowserBlankHTM = strFilename
End Function
Note: the file Blank.htm is only created if it does not already exist.