title: Handle incorrect values passed to an Access VBA function
body: <p>I have a VBA function that is basically along these lines:</p>
  
  <pre><code>Public Function JoinDateTime(DateTime As String, Time As String) As Date
      Dim dtDate As Date
      dtDate = CDate(Format(DateTime, "dd/mm/yyyy"))
      dtDate = dtDate &amp; " " &amp; Format(Time, "hh:mm")
      JoinDateTime = dtDate
  End Function
  </code></pre>
  
  <p>It glues a date and a time together into a datetime value.  (The real function has some more logic behind it.)</p>
  
  <p>The problem is, I'd like to add handling for annoying values being passed to it. This is mostly for empty/null values - if DateTime is empty, return empty.  If it's a text string returning #Error so it doesn't just fail silently seems like a good idea.</p>
  
  <p>Problem is, I'm not sure how to do so.  I'd thought about doing an early return, maybe something like shoving this at the start of the function:</p>
  
  <pre><code>If DateTime = Null or DateTime = "" Then 
      JoinDateTime = Null
  End If
  </code></pre>
  
  <p>but it doesn't seem to consider that as a return and still executes the rest of the function.</p>
  
  <p>Is there a way to do this?  A better way, ideally?</p>