Hi All. I need some help with my report and their subsequent subreports. Currently I am generating a report with 3 separate sub reports and all the reports are based on a series of parameters specified on a form (ie. Start Date, End Date, ID, etc...). Each sub report is based off it's own query and is linked to the main report by a specific ID. What I'm trying to do is run the report and have it automatically split itself for each record and then save each record as it's own PDF.
Here's the code as I have it, and it does not work. Every move leads me to a new error.:banghead:
Any and all help is greatly appreciated!
Here's the code as I have it, and it does not work. Every move leads me to a new error.:banghead:
Code:
Private Sub cmdReport_Click()
Dim ReportName As String
ReportName = Me.cmboReport
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdfSnow As QueryDef
Dim qdfUtilities As QueryDef
Dim qdfPestControl As QueryDef
Dim qdfProperty As QueryDef
If ReportName = "Spend by Property" Then
Set db = CurrentDb
Set qdfSnow = db.QueryDefs("qrySnowSpend") 'My parameter query for a subreport
Set qdfUtilities = db.QueryDefs("qryUtilitySpend") 'My parameter query for a subreport
Set qdfPestControl = db.QueryDefs("qryPestControlSpend") 'My parameter query for a subreport
Set qdfProperty = db.QueryDefs("qryActivePropertiesReport") 'My parameter query for the main report
qdfSnow.Parameters("DatePaid") = [Forms]![frmReportMenu]![rptStartDate] & [Forms]![frmReportMenu]![rptEndDate] 'Form control
qdfUtilities.Parameters("DatePaid") = [Forms]![frmReportMenu]![rptStartDate] & [Forms]![frmReportMenu]![rptEndDate] 'Form control
qdfPestControl.Parameters("DatePaid") = [Forms]![frmReportMenu]![rptStartDate] & [Forms]![frmReportMenu]![rptEndDate] 'Form control
Set rst = qdfProperty.OpenRecordset 'set qdfProperty as Recordset because this is the main report. All other qdf's are subreports.
Do While Not rst.EOF
strRptFilter = "[PropID] = " & rst.Fields("propName")
DoCmd.OutputTo acOutputReport, "Spend by Property", acFormatPDF, "z:\Utilities\Real Estate Database Project\Test" & "\" & rst.Fields("propName") & Format(Date, "mmddyyyy") & ".pdf"
DoEvents
rst.MoveNext
Loop
rst.Close
DoCmd.OpenReport ReportName, acPreview
'DoCmd.OpenReport stDocName, acNormal, , "[propID] = " & Me.txtPropID
Else
DoCmd.OpenReport ReportName, acPreview
End If
End Sub
Any and all help is greatly appreciated!