title: Setting the Data Source for a Report
body: <p>I'm trying to make a button in an Access form which will run a couple queries and then take the resultant recordsets and put them into reports. I have gotten to the point where the button will call the module, it creates the proper recordsets, and then it creates the reports. However, the reports are blank, they don't have the data in them from the recordsets. I think my problem is that I haven't properly assigned the data source of the reports but I can't figure out how to if that is the issue.</p>
  
  <pre><code>Private Function showReport(sectionHeading As String, SQL As String, recordset As ADODB.Recordset)
  Dim textBox As Access.textBox ' textbox control
  Dim label As Access.label ' label control
  Dim report As report ' hold report object
  Dim controlTop As Long ' holds top value of control position
  Dim controlLeft As Long ' holds left value of control position
  Dim title As String 'holds title of report
  Dim i As Integer 'iterator
  i = 0
  
  title = sectionHeading
  
  controlLeft = 0
  controlTop = 0
  
  Set report = CreateReport
  
  report.Width = 8500
  report.Caption = title
  
  Set label = CreateReportControl(report.Name, acLabel, _
  acPageHeader, , "Title", 0, 0)
  label.FontBold = True
  label.FontSize = 12
  label.SizeToFit
  
  For Each fld In recordset.fields
      Set textBox = CreateReportControl(report.Name, acTextBox, _
      acDetail, , fld.Name, controlLeft + 1500, controlTop)
      textBox.SizeToFit
  
      Set label = CreateReportControl(report.Name, acLabel, acDetail, _
      textBox.Name, fld.Name, controlLeft, controlTop, 1400, textBox.Height)
      label.SizeToFit
  
      controlTop = controlTop + textBox.Height + 25
  
      i = i + 1
  Next
  
  Set label = CreateReportControl(report.Name, acLabel, _
  acPageFooter, , Now(), 0, 0)
  
  Set textBox = CreateReportControl(report.Name, acTextBox, _
  acPageFooter, , "='Page ' &amp; [Page] &amp; ' of ' &amp; [Pages]", report.Width - 1000, 0)
  textBox.SizeToFit
  
  report.RecordSource = SQL
  
  DoCmd.OpenReport report.Name, acViewPreview
  
  recordset.Close
  Set recordset = Nothing
  Set report = Nothing
  End Function
  </code></pre>