title: Check if a query exists using VBA
body: <p>I have a procedure in VBA which runs a report based on what user select on a dropdown (Report Name and grouping criteria) in a form. Also, I have a button which that user selection can be transferred to Excel.
  The part of the procedure where I want to test if the query exist is below:</p>
  
  <pre><code>If Not IsNull(Me.cmbGroup.Value) Or Me.cmbGroup.Value = "" Then
  
      strSQL = "SELECT * FROM qryCrossTotGroup WHERE [Group]='" &amp; Me.cmbGroup.Value &amp; "'"
      'MsgBox strSQL
  
      With MyDatabase
          .QueryDefs.Delete ("tmpOutQry")
          Set MyQueryDef = .CreateQueryDef("tmpOutQry", strSQL)
      End With
  
      'Step 3: Open the query
      Set MyRecordset = MyDatabase.OpenRecordset(strSQL)
  
      'Step 4: Clear previous contents
      Dim xlApp As Object
      Set xlApp = CreateObject("Excel.Application")
      With xlApp
          .Visible = True
          .Workbooks.Add
          .Sheets("Sheet1").Select
  
      'Step 5: Copy the recordset to Excel
          .ActiveSheet.Range("A2").CopyFromRecordset MyRecordset
  
      'Step 6: Add column heading names to the spreadsheet
          For i = 1 To MyRecordset.Fields.Count
              xlApp.ActiveSheet.Cells(1, i).Value = MyRecordset.Fields(i - 1).Name
          Next i
          xlApp.Cells.EntireColumn.AutoFit
      End With
  
  End If
  </code></pre>
  
  <p>I want to test if query "tmpOutQry" exist in order to delete it. Have someone that line of code?</p>