Problem with occasional permission denied '70' error, when user clicks table cell, in locally generated and loaded html document.
VB6 form, where webbrowser component;
- loads locally generated html file from local disk (WebBrowser1.Navigate2 absolutepathandfilename.html) and other usual stuff in document complete event, to make sure document is loaded.
- html document is plain html file without any javascript, frames or embedded objects.
- document is well formed and W3C validator (https://validator.w3.org/) validates it succesfully.
Error happens if/when user clicks 'directly' to ts7 cell, without first clicking somewhere else in webbrowser component area - but this is not consistent ie. does not happen avery time. Somehow it is linked to what is in table cell content fex. 1.0330 throws error every time, but 1.0338 never.
Workaround is to add On Error statement.
Any idea why error happens?
VB6 form, where webbrowser component;
- loads locally generated html file from local disk (WebBrowser1.Navigate2 absolutepathandfilename.html) and other usual stuff in document complete event, to make sure document is loaded.
- html document is plain html file without any javascript, frames or embedded objects.
- document is well formed and W3C validator (https://validator.w3.org/) validates it succesfully.
Code:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser1.object) Then 'HTML document is ready
Set objHTMLDoc = WebBrowser1.Document
If (objHTMLDoc Is Nothing) = False Then
bDocComplete = True
'lhwnd = WebBrowser1.hwnd 'throws 80004005 error (access denied)
WebBrowser1.SetFocus 'Does not work
Else
MsgBox "Unable to initialize html document " & vbCrLf & sHtmlDocFile , vbExclamation + vbOKOnly
End If
Else
MsgBox "Unable to instantiate webbrowser object.", vbExclamation + vbOKOnly
End If
Code:
Private Function objHTMLDoc_onclick() As Boolean
If objHTMLDoc.activeElement.className = "ts7" Then
objHTMLDoc.activeElement.Style.backgroundColor = "SpringGreen" 'Feedback for user -> active selected table cell.
sSelectedHTMLCode = CStr(objHTMLDoc.activeElement.outerText) 'OuterText contains clicked table cell text data.
If (objClicked Is Nothing) = False Then
'On Error Resume Next 'Workaround for the first round, when objClicked is nothing
If (TypeOf objClicked Is IHTMLTableCell) Then 'IHTMLTableCell
If sPreviousSelectedCode <> sSelectedHTMLCode Then
objClicked.Style.background = "White" 'Restore previous selection 'Occasional permission denied error '70'
End If
End If
End If
Set objClicked = objHTMLDoc.activeElement
sPreviousHTMLCode = sSelectedHTMLCode
End Sub
Workaround is to add On Error statement.
Code:
If sHTMLPreviousMatKoodi <> sHTMLMatkoodi Then
On Error Resume Next 'Premission denied error '70' prevention
objClicked.Style.background "White" 'Restore previous selection