Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Null is never equal to anything, not even Null. Use the <code>IsNull()</code> function.</p> <pre class="lang-vb prettyprint-override"><code>If IsNull(Me.textbox.Value) Then </code></pre> <p>If you want <code>Me.textbox</code> treated the same when it contains an empty string as when it's Null, concatenate an empty string to it and check the length of the combined string:</p> <pre class="lang-vb prettyprint-override"><code>If Len(Me.textbox.Value &amp; "") = 0 Then </code></pre> <p>You could also use the named constant, <code>vbNullString</code>, instead of the string literal, <code>""</code>, for an empty string. </p> <pre class="lang-vb prettyprint-override"><code>If Len(Me.textbox.Value &amp; vbNullString) = 0 Then </code></pre> <p>Using the string literal requires VBA to construct that string from scratch each time. With the named constant, VBA only needs to reference it, so should be faster and use less memory. However in many (probably most) cases, the performance advantage with <code>vbNullString</code> would be so minor that you wouldn't notice the difference. Also see the <a href="https://stackoverflow.com/questions/5662751/textbox-null-problem/5663965#comment6529056_5663965">comment below</a> from <a href="https://stackoverflow.com/users/9787/david-w-fenton">David-W-Fenton</a>.</p> <p>For me, the more compelling reason to use <code>vbNullString</code> is that it's instantly recognizable to my aging eyes. Conversely, with the string literal, it takes (a tiny bit) longer for me to confirm that <code>""</code> is not actually something else ... like <code>" "</code> or <code>"'"</code>. The only downside with <code>vbNullString</code>, IMO, is that requires more typing than <code>""</code>. </p> <p>And finally, although you don't actually need to explicitly reference the <code>Value</code> property (since it's the default property of a text box), I left it in because you had it that way and because I prefer to be explicit with <code>Value</code>, too. :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload