.NET Programming
--
Questions
--
Followers
Top Experts
SHDocVW.InternetExplorer. I have a datagrid that when you click on an item in a column it should load a corresponding web page. The problem is if you close the web page after it opens and then try to open another one it crashes with this error (sadly inside my error handler on the line where I go either 'myexplorer = new shdocvw.internetexplorer' which should just release the handle and give me a new one, or even if I try to do a 'myexplorer = Â nothing' first..)
ERROR:
The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))
The function it occurs inside is here:
  Private Sub openWebPage(ByVal webURL$)
    Dim pageReset As Boolean = False
    On Error GoTo ResetWebPage
    LoadWebPageByUrl(webURL)
    Exit Sub
ResetWebPage:
    If pageReset = False Then
      Err.Clear()
      AttemptToClosePage()
      myExplorer = New SHDocVw.InternetExplorer <= CRASHES ON THIS LINE!
      pageReset = True
      LoadWebPageByUrl(webURL)
      Exit Sub
    End If
  End Sub
Any help on this matter would be greatly appreciated. The whole problem should be as simple as resetting the object that is 'myExplorer' but for some reason that does not work as it would in vb6.
Thanks Experts! ~ Michael
Here is all the related code:
  Private Sub myDataGrid_CurrentCellChan
    Dim col As Integer = Me.myDataGrid.CurrentCell.
    Dim row As Integer = Me.myDataGrid.CurrentCell.
    'On Error GoTo Whatever
    Dim cellVal$ = nz(Me.myDataGrid.Item(row,
    If Me.myDataGrid.TableStyles(
    Dim colName$ = Me.myDataGrid.TableStyles(
    'Dim colName$ = myDB.myDS.Tables(gTableLoa
    'MsgBox(row & vbCrLf & col)
    If Not colName = "RecNum" Then Exit Sub
    If cellVal <> "" Then
      Dim newurl = makeUrl(cellVal)
      If newurl <> "" Then openWebPage(newurl)
    End If
Whatever:
  End Sub
Private Sub openWebPage(ByVal webURL$)
    Dim pageReset As Boolean = False
    On Error GoTo ResetWebPage
    LoadWebPageByUrl(webURL)
    Exit Sub
ResetWebPage:
    If pageReset = False Then
      Err.Clear()
      AttemptToClosePage()
      myExplorer = New SHDocVw.InternetExplorer <= CRASHES ON THIS LINE!
      pageReset = True
      LoadWebPageByUrl(webURL)
      Exit Sub
    End If
  End Sub
  Private Function makeUrl(ByVal recNum$) As String
    Dim suffix$ = ""
    If InStr("ABCDEFGHIJKLMNOPQRS
      suffix = recNum(Len(recNum))   'we have a letter
      recNum = Mid(recNum, 1, Len(recNum) - 1)
    End If
    makeUrl = "about:blank"
    makeUrl = Replace(Replace(gRecorderU
  End Function
  Private Sub LoadWebPageByUrl(ByVal webUrl$)
    Me.fldDoing.Text = "Opening Web Page.."
    With myExplorer
      .Navigate(webUrl)
      waitForDoc(myExplorer)
      'set the PDF option checkbox to false & submit form to go to file
      .Document.Forms("frmMain")
      .Document.Forms("frmMain")
      .Document.Forms("frmMain")
      .Visible = True
    End With
    Me.fldDoing.Text = ""
    'Try to figure out here how to set the focus of this window
  End Sub
  Private Sub AttemptToClosePage()
    On Error GoTo JustLeaveSub
    myExplorer.Quit()
    myExplorer.Visible = False
JustLeaveSub:
  End Sub
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
 .Document.Forms("frmMain")
      .Document.Forms("frmMain")
      .Document.Forms("frmMain")
which then finally loads the right page. It doesn't actually go directly to the page. So I'm willing to try the above code, The Learned One, but I'm anticapating already it won't actually help me..
Bob






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
~Michael
Version: 6.0.2900.2180.xpsp_sp2_gdr
Bob

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
So you're saying the old com library can't be made to work? I thought that was something you could do in .net, is use the older com libraries?
~Michael
(Yeah my friend has some experience using the new one and he says that overall in .net microsoft made no great improvements or any new things to the webbrowser object, and in fact actually made it /more/ difficult to use...)
Public WithEvents myExplorer As New SHDocVw.InternetExplorer
Bob






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
The key was to encapsulate it with a try/except block instead of using the on error goto, which the documentation claimed worked the same way, even tho it's vb6, but ha, I've found proof that it doesn't handle them the same. Anyways, thanks for your help The Learned One. I'm going to take your first answer because technically it would circumvent the problem and could've been a possible solution, if I wasn't so picky. As well as using the new webbrowser, that was good too.. I just don't feel like the effort today.. :)
Here is the working code:
  Public Sub openWebPage(ByVal webURL$)
    Dim pageReset As Boolean = False
    Try
      LoadWebPageByUrl(webURL)
    Catch ex As Exception
      Err.Clear()
      AttemptToClosePage()
      ' myExplorer = Nothing
      myExplorer = New SHDocVw.InternetExplorer
      pageReset = True
      LoadWebPageByUrl(webURL)
    End Try
  End Sub
  Public Sub LoadWebPageByUrl(ByVal webUrl$)
    Main.fldDoing.Text = "Opening Web Page.."
    With myExplorer
      .Navigate(webUrl)
      waitForDoc(myExplorer)
      'set the PDF option checkbox to false & submit form to go to file
      .Document.Forms("frmMain")
      .Document.Forms("frmMain")
      .Document.Forms("frmMain")
      .Visible = True
    End With
    Main.fldDoing.Text = ""
    'Try to figure out here how to set the focus of this window
  End Sub
.NET Programming
--
Questions
--
Followers
Top Experts
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.