title: "Invalid use of Null" when using Str() with a Null Recordset field, but Str(Null) works fine
body: <p>I'm banging my head against the wall on this one. I was looking at some old database reporting code written in VB6 and came across this line (the code is moving data from a "source" database into a reporting database):</p>
  
  <pre><code>rsTarget!VehYear = Trim(Str(rsSource!VehYear))
  </code></pre>
  
  <p>When <code>rsSource!VehYear</code> is <code>Null</code>, the above line generates an "Invalid use of Null" run-time error. If I break on the above line and type the following in the Immediate pane:</p>
  
  <pre><code>?rsSource!VehYear
  </code></pre>
  
  <p>It outputs <code>Null</code>. Fine, that makes sense. Next, I try to reproduce the error:</p>
  
  <pre><code>?Str(rsSource!VehYear)
  </code></pre>
  
  <p>I get an "Invalid use of Null" error.</p>
  
  <p>However, if I type the following into the Immediate window:</p>
  
  <pre><code>?Str(Null)
  </code></pre>
  
  <p>I don't get an error. It simply outputs <code>Null</code>.</p>
  
  <p>If I repeat the same experiment with <code>Trim()</code> instead of <code>Str()</code>, everything works fine. <code>?Trim(rsSource!VehYear)</code> returns <code>Null</code>, as does <code>?Trim(Null)</code>. No run-time errors.</p>
  
  <p>So, my question is, how can <code>Str(rsSource!VehYear)</code> possibly throw an "Invalid use of Null" error when <code>Str(Null)</code> does not, when I <strong>know</strong> that <code>rsSource!VehYear</code> is equal to <code>Null</code>?</p>
  
  <hr>
  
  <p><strong>Update:</strong> If I type the following in the Immediate window, it works as expected (no error occurs):</p>
  
  <pre><code>?Str(rsSource!VehYear.Value)
  </code></pre>
  
  <p>This outputs <code>Null</code>. Now, I know that <code>rsSource!VehYear</code> is actually an <code>ADODB.Field</code> instance, but <code>Value</code> is its default property, so <code>Str</code> should be operating on the <code>Value</code> property (which is <code>Null</code>). Even the error message ("Invalid use of Null") suggests that <code>Str</code> is receiving a <code>Null</code> parameter, but how can it treat <code>Null</code> differently in one case and not the other?</p>
  
  <p>My only guess is the internal implementation of <code>Str()</code> is somehow failing to get the default property, and the "Invalid use of Null" error is happening for a different reason (something other than the parameter is causing the "Invalid use of Null", perhaps when it is trying to retrieve the default property from the <code>Field</code> object). </p>
  
  <p>Does anyone have a more detailed, technical explanation for what is actually happening here?</p>
  
  <p>In short:</p>
  
  <pre><code>?Str(rsSource!VehYear)
  </code></pre>
  
  <p>throws an "Invalid use of Null" error when <code>rsSource!VehYear</code> is <code>Null</code>, but</p>
  
  <pre><code>?Str(rsSource!VehYear.Value)
  </code></pre>
  
  <p>returns <code>Null</code>.</p>
  
  <p>However, both <code>Trim(rsSource!VehYear)</code> and <code>Trim(rsSource!VehYear.Value)</code> return <code>Null</code>.</p>