title: Microsoft Access - Crosstab of a filtered form
body: <p>I'm trying to generate a report similar to a crosstab. The data are from a filtered form (<em>Dates</em> and <em>WorkerID</em> (String)).</p>
  
  <ul>
  <li>form: <em>frmReg</em> </li>
  <li>table with data: <em>tReg</em> </li>
  <li>report: <em>reportReg</em></li>
  </ul>
  
  <p>On the following line:</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>Set qdf = dbsReport.QueryDefs(Me.RecordSource)
  </code></pre>
  
  <p>I'm getting the error:</p>
  
  <blockquote>
    <p>Error 3265 Item not found in this collection</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub Report_Open(Cancel As Integer)
   '  Create underlying recordset for report using criteria
  
      Dim intX As Integer
      Dim qdf As QueryDef
      Dim frm As Form
  
      '   Don't open report if frmReg form isn't loaded.
      If Not (IsLoaded("frmReg")) Then
          Cancel = True
          MsgBox "To preview or print this report, you must open " _
                  &amp; "frmReg in Form view.", vbExclamation, _
                 "Must Open Dialog Box"
          Exit Sub
      End If
  
      '  Set database variable to current database.
      Set dbsReport = CurrentDb
      Set frm = Forms!frmReg
  
      '  Open QueryDef object.
      ' Set qdf = dbsReport.QueryDefs("ReportReg")
       Me.RecordSource = "SELECT * FROM [tReg]"
       Set qdf = dbsReport.QueryDefs(Me.RecordSource)
  
      '  Open Recordset object.
      Set rstReport = qdf.OpenRecordset()
  
      '  Set a variable to hold number of columns in crosstab query.
      intColumnCount = rstReport.Fields.Count
  End Sub
  </code></pre>