'When creating a pdf from a report, sub-reports won't show if they have no data and I want it to

I have a report that is made up of 4 sub-reports. This report is made up of multiple physicians, and I've been successful creating a button that will take this large report, break it up by the physicians [EPIC_ID], and create a pdf file with each physicians specific information.

My problem is, when 1 of those 4 sub-reports has no data, the report with no data isn't shown in the final pdf.

When I run and view the report (in report view), it will show all 4 reports with the physician information regardless if there is data for each report, but when I go to print view, it will only show the reports that have data.

I need to be able to create a pdf that will show the subreports even if there is no data in it.

I've tried creating a text box that only shows when there is no data. And it works in the report view, but not in print view or when I make it a pdf. I've also tried using a label and the "On No Data" portion of the sub-reports, but that didn't work.

Any help would be appreciated! Below is the code to the button that opens the report and makes them in to pdf files:

Private Sub Command0_Click()
Dim rst As DAO.Recordset
Dim strFolder1 As String, strFolder2

DoCmd.OpenQuery "qryPhysicianID_Range_tbl"

Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT [Prov_Order_Name],[EPIC_ID] FROM  [tblPhysicianID_Range] ORDER BY [EPIC_ID];", dbOpenSnapshot)

If rst.RecordCount > 0 Then ' make sure that we have data

    rst.MoveFirst

Do While Not rst.EOF
        
    strFolder1 = "U:\Co\Physician\Reappointment\Jordans Test\" 'common folder for files to go
    
    strFolder2 = strFolder1 & rst.Fields("[Prov_Order_Name]") & "\" 'creates folder by Provider Name
    If Dir(strFolder2, vbDirectory) = "" Then MkDir strFolder2 'determines if folder exists or not, and if it doesn't it makes one
    
    DoEvents
    rst.MoveNext
Loop

End If

 If rst.RecordCount > 0 Then ' make sure that we have data

    rst.MoveFirst

 Do While Not rst.EOF
 
 strRptFilter = "[EPIC_ID] = " & rst![EPIC_ID]

   strFolder1 = "U:\Co\Physician\Reappointment\Jordans Test\" 'common folder for files to go
      
     DoCmd.OpenReport "rptCombined", acViewPreview, , strRptFilter, acHidden ' open the report hidden in preview mode setting the where parameter
     
    DoCmd.OutputTo acOutputReport, "rptCombined", acFormatPDF, _
   strFolder1 & rst.Fields("[Prov_Order_Name]") & "\" & rst.Fields("[Prov_Order_Name]") & ".pdf", _
   , , , acExportQualityScreen ' save the opened report

    DoCmd.Close acReport, "rptCombined" ' close the report
    
    DoEvents
    rst.MoveNext
Loop

End If

rst.Close
Set rst = Nothing
End Sub


Solution 1:[1]

Use code behind main report to manage display of label or textbox control when subreport does not have data. Example:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.lblOU.Visible = Not Me.ctrOU.Report.HasData
Me.lblCO.Visible = Not Me.ctrCO.Report.HasData
Me.lblRC.Visible = Not Me.ctrRC.Report.HasData
End Sub

Procedure is OnFormat event of main report Detail section. Example shows use of label control. Use whatever you prefer and modify code as appropriate for your objects and their names. Add the 4th control code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1