title: SQL with no matches found causes MsgBox
body: <p>My form takes the data the user entered, constructs a SQL statement and returns the results. I would like to have a message box pop up when there are no matches found.</p>
  
  <p>My current code/idea:</p>
  
  <pre><code>If qdf.sql = 0 Then
          MsgBox "No clients matching your information." &amp; _
          vbCrLf &amp; "have been found. Please try again." &amp; _
          , vbCritical, "No Matches"
      Else
          DoCmd.OpenForm "frmSearchResults"
          Me.Visible = False
  End If
  </code></pre>
  
  <p>I'm having trouble figuring out the correct syntax for <code>if qdf.sql = 0</code> . </p>
  
  <p><strong>UPDATE: Full query</strong></p>
  
  <pre><code>Private Sub cmdSearch_Click()
  
  'On Error GoTo cmdSearch_Click_err
  
  Dim db As Database
  Dim strSQL As String
  Dim rs As DAO.Recordset
  Dim qdf As QueryDef
  Dim strClientID As String
  Dim strLastName As String
  Dim strFirstName As String
  Dim strDOB As String
  
  Set db = CurrentDb
  Set rs = db.OpenRecordset(qdf.sql)
  
  ' call QueryCheck module to determine if query exists
  If Not QueryExists("qrySearch") Then
      Set qdf = db.CreateQueryDef("qrySearch")
  Else
      Set qdf = db.QueryDefs("qrySearch")
  End If
  
  ' handle nulls in the user's entries
      If IsNull(Me.txtClientID.Value) Then
          strClientID = " Like '*' "
          Else
          strClientID = "='" &amp; Me.txtClientID.Value &amp; "' "
      End If
  
      If IsNull(Me.txtLastName.Value) Then
          strLastName = " Like '*' "
          Else
          strLastName = " Like '" &amp; Me.txtLastName.Value &amp; "*' "
      End If
  
      If IsNull(Me.txtFirstName.Value) Then
          strFirstName = " Like '*' "
          Else
          strFirstName = " Like '*" &amp; Me.txtFirstName.Value &amp; "*' "
      End If
  
      If IsNull(Me.txtDOB.Value) Then
          strDOB = " Like '*' "
          Else
          strDOB = "='" &amp; Me.txtDOB.Value &amp; "' "
      End If
  
  strSQL = "SELECT Clients.* " &amp; _
           "FROM Clients " &amp; _
           "WHERE Clients.clientid" &amp; strClientID &amp; _
           "AND Clients.namelast" &amp; strLastName &amp; _
           "AND Clients.namefirst" &amp; strFirstName &amp; _
           "AND Clients.birthdate" &amp; strDOB &amp; _
           "ORDER BY Clients.namelast,Clients.namefirst;"
  
  Debug.Print strSQL
  
  ' check to see if the results form is open and close if it is
  DoCmd.Echo False
  
  If Application.SysCmd(acSysCmdGetObjectState, acForm, "frmSearchResults") = acObjStateOpen Then
      DoCmd.Close acForm, "frmSearchResults"
  End If
  
  ' run SQL statment
  qdf.sql = strSQL
  
  ' check for no matches found
      If rs.RecordCount = 0 Then
          MsgBox "No clients matching your information were found." &amp; _
          vbCrLf &amp; "Please search again.", vbInformation, "No Matches"
      Else
          DoCmd.OpenForm "frmSearchResults"
          Me.Visible = False
      End If
  
  'cmdSearch_Click_exit:
  '    DoCmd.Echo True
  '    Set qdf = Nothing
  '    Set db = Nothing
  
  'Exit Sub
  
  'cmdSearch_Click_err:
  '        MsgBox "An unexpected error has occurred." &amp; _
  '        vbCrLf &amp; "Please note of the following details and contact the EIIS support desk:" &amp; _
  '        vbCrLf &amp; "Error Number: " &amp; Err.Number &amp; _
  '        vbCrLf &amp; "Description: " &amp; Err.Description _
  '        , vbCritical, "Error"
  '    Resume cmdSearch_Click_exit
  
  End Sub
  </code></pre>