title: "invalid use of null" for vba function that returns variant
body: <p>I'm trying to write a VBA function that gets a value from an Access table using a SELECT query.  Here's the code:</p>
  
  <pre><code>Function getTableValue(uniqueID As Long, tableName As String, _ 
  idField As String, tableField As String) As Variant
  
  Dim db As Database
  Dim rs As Recordset
  Dim selectSQL As String
  
  selectSQL = "select * from " &amp; tableName &amp; " where " &amp; idField &amp; "=" &amp; uniqueID
  
  Set db = OpenDatabase(dbPath)
  Set rs = db.OpenRecordset(selectSQL)
  
  If rs.RecordCount &gt; 0 Then
      rs.MoveLast
      rs.MoveFirst
      getTableValue = rs.Fields(tableField)
  End If
  
  End Function
  </code></pre>
  
  <p>When the field specified by <code>tableField</code> is a Date/Time type and the field is empty, <code>getTableValue()</code> returns an "Invalid use of Null" error.  I thought that having the function return a Variant would allow me to return Null values; what should I do to handle these empty dates?</p>