title: Testing if object Is Nothing results in 'Object required' error
body: <p>I am supporting some classic ASP pages, one of which uses and re-uses an object <strong>conn</strong> and disposes of it either when the .asp page finishes processing or right before the page redirects to another page.</p>
  
  <pre><code>&lt;%
  dim conn
  ...
  set conn = server.CreateObject("adodb.connection")
  ...
  sub cleanUp()
      conn.Close
      set conn = nothing
  end sub
  ...
  sub pageRedirect(url)
      call cleanUp()
      response.Redirect url : response.End
  end sub
  ...
  ' very end of file
  call cleanUp()%&gt;
  </code></pre>
  
  <p>I've found that if there is a redirect, I get a server error right at the line <code>conn.Close</code>, <em>Microsoft VBScript runtime error '800a01a8' Object required</em>. I figure there's no reason why that line would execute more than once but to be safe I rewrote the function</p>
  
  <pre><code>sub cleanUp()
      if(not (conn Is Nothing)) then
          conn.Close
          set conn = Nothing
      end if
  end sub
  </code></pre>
  
  <p>But I still get that exact error, now at the line <code>if(not (conn Is Nothing))</code>!! I thought the purpose of <code>Is Nothing</code> was to do a test before using the variable name conn precisely to prevent that 'object required' error, but the test is throwing the same error.</p>
  
  <p>What other test can I use to make sure conn isn't referenced if it'd already been set to Nothing?</p>