title: How to test if item exists in recordset?
body: <p>I have a crosstab query that is being loaded into a recordset. I'm then writing the query fields to an Excel spreadsheet. The problem is that a field may not exist based on the query results. </p>
  
  <p>For example, I have the following line:</p>
  
  <pre><code>oSheet5.Range("F1").Value = rsB2("AK")
  </code></pre>
  
  <p>...which would write the value of the recordset item named "AK" to the spreadsheet. But if "AK" doesn't exist, I get an error <code>Item not found in this collection</code>.</p>
  
  <p>How I can I test to see if there's an item named "AK"?</p>
  
  <p>I tried...</p>
  
  <pre><code>If rsB2("AK") Then
      oSheet5.Range("F" &amp; Count).Value = rsB2("AK")
  End If
  </code></pre>
  
  <p>...but that didn't work.</p>
  
  <p>I also tried...</p>
  
  <pre><code>If rsB2("AK") Is Nothing Then
      oSheet5.Range("F" &amp; Count).Value = ""
  Else
      oSheet5.Range("F" &amp; Count).Value = rsB2("AK")
  End If
  </code></pre>
  
  <p>...and still the same error.</p>
  
  <p>There are 50+ items/fields to check .. all states in USA plus a few extras.
  Thanks!</p>