title: Error when trying to access DOM using SHDocVw.InternetExplorer.Document
body: <p>I can see this being a simple correction however it has me stumped.</p>
  
  <p>This is the error I am getting</p>
  
  <p>COMException was unhandled</p>
  
  <p>Error HRESULT E_FAIL has been returned from a call to a COM component.</p>
  
  <p>This is the code (I have blanked out the URL however they are valid)</p>
  
  <pre><code>class SMSHandler
  {
      private InternetExplorer ie;
      private object URL = "##########";
      private object URL2 = "###########";
  
      public SMSHandler()
      {
          ie = new InternetExplorer();
          ie.Visible = true;
      }
  
      public void openMACS()
      {
          object Empty = 0;
  
          ie.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);
  
          while (ie.Busy);
  
          ie.Navigate2(ref URL2, ref Empty, ref Empty, ref Empty, ref Empty);
  
          IHTMLDocument2 HTMLDoc = (IHTMLDocument2)ie.Document;
  
      }
  </code></pre>
  
  <p>This is the line that is generating the error</p>
  
  <pre><code>IHTMLDocument2 HTMLDoc = (IHTMLDocument2)ie.Document;
  </code></pre>
  
  <p>The web page opens fine however when I try to assign the Document to the IHTMLDocument2 it fails.</p>
  
  <p>Any help would be great</p>