title: #Error in DLookup Function
body: <p>I am using a function in MS Access to return a Query field value with a DLookup.  The function passes a value to <code>strPersonType</code> from an existing field in the query.</p>
  
  <p>The function works fine when there is a value present in that field, however when there is no value present it returns <code>#Error</code>. In that case I would like it to return a <code>Null</code> or blank value.</p>
  
  <p>I have tried error handling and <code>If</code> statements (like the one below) and I have been unable to fix it thus far.</p>
  
  <p>No matter what I try the field value comes up as <code>#Error</code>.</p>
  
  <pre><code>Function LookUpPersonType2(strPersonType As String)            
      'Used to look up Person Type2 in the "Person Type Key" table given PERSON_TYPE
      'Returns original supplied name if no variation
  
  
      If IsNull(strPersonType) Or strPersonType = "" Then
          LookUpPersonType2 = ""
      Else
  
          If IsNull(DLookup("[Person Type2]", "[Person Type Key]", "[PERSON_TYPE] ='" &amp; strPersonType &amp; "'")) Then
              LookUpPersonType2 = strPersonType
          Else
              LookUpPersonType2 = DLookup("[Person Type2]", "[Person Type Key]", "[PERSON_TYPE] ='" &amp; strPersonType &amp; "'")
          End If
      End If
      Debug.Print LookUpPersonType2 &amp; ","
  End Function
  </code></pre>