I am trying to display the results of a recordset inside of a report that I made, my process is that I select a year on a form then click a button, once that button is clicked it sends that year to the report and runs the following Report_Open code:
Private Sub Report_Open(Cancel As Integer)
Dim rst As Recordset
Dim qdf As QueryDef
Dim subReport As Report
If Not IsNull(OpenArgs) Then
Set qdf = CurrentDb.QueryDefs("qry")
qdf.Parameters("[Year]").Value = OpenArgs
Set rst = qdf.OpenRecordset()
qdf.Close
'Code to fill the report'
'''''''''''''''''''''''''
Else
DoCmd.Close
End If
End Sub
I am trying to get the results of that recordset to be displayed on my Report. due to the nature of the query, the results can vary drastically so I can't just set the results in a set amount of textboxes.
I was trying to set the Report's RecordSource to this recordset but I learned you can't do that with recordsets. I'm very new to how to make reports so I've been stuck on this for a few days and feel a bit defeated. Any help is really appreciated.
This is not how you do it in Access. Directly assign your query name to the record source of your report. Access will then create the Recordset automatically.
You can then open the report by specifying a where-clause:
If you have to compare the year against a Date/Time column, the condition will look like this:
"Year(myDateColumn) = " & theYear