Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Make Subreport Display Something When Recordset is Empty

Posted on 2008-10-15
7
Medium Priority
?
504 Views
Last Modified: 2013-11-28
Is there a way to show a subreport's header if the subreport has no data? On a work order report (rptWorkOrder), I have two subreports, one for parts charges (subreportParts) and another for labor charges (subreportLabor). Both subreports are set to can grow=yes and can shrink=no, and both are height=1". If the recordset for subreportParts is empty the subreport is not visible, leaving a 1" in my report.

I would like to put a label under the subreportParts, make it visible if the subreportParts recordset is empty, and set subreportParts.height=lblParts.height on the parent report's on format event - but a label does not have a height property. Any suggestions?
0
Comment
Question by:roverturf
  • 3
  • 2
  • 2
7 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 2000 total points
ID: 22726465
Make a subreport like rptNoData that is only a Lable with text like "No records" and place it above the subreportParts.. Make this report Visible propertie to No.

On the main report, On No Data event, put this code:

Private Sub Report_NoData(Cancel As Integer)
    Report!rptNoData .Visible = True
End Sub

jppinto
0
 

Author Comment

by:roverturf
ID: 22740941
Thanks, jppinto.   I'll try your idea and post my findings back to this thread.

-Richard
0
 
LVL 33

Expert Comment

by:jppinto
ID: 22743724
Did you've tryed my sugestion?

jppinto
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22744647
roverturf,

Why are the subreports  1" tall?

If you set the Can Grow and the Can Shrink properties of the subReport to: YES, the control will grow and shrink based on the number of records it displays.

So, you could really make the subform .1 inches tall and it will display the records just fine.

Look at these screenshots:

JeffCoachman
Skinny-SubReport.JPG
LongSubReport.JPG
0
 

Author Closing Comment

by:roverturf
ID: 31509045
Thanks, jppinto.  
Using your suggestion, I built a work order report (portrait, 8.5x11) that had two 1" tall subreports to show parts used.  
Subrpt1 held a recordsource which showed parts used for the work order report (parent).  
Subrpt2 was a copy of subrpt1 with the Detail Section removed and without a recordsource.
On the parent report's Detail SectionOnFormat event I added:

    '/ If the subrpt has no data then show the empty placeholder rpt
    If Me.subrptWoParts.Report.HasData Then
        Me.subrptWoParts.Visible = True
        Me.subrptWoParts_Placeholder.Visible = False
    Else
        Me.subrptWoParts.Visible = False
        Me.subrptWoParts_Placeholder.Visible = True
    End If

So.. if the subrptWoParts had data, the parts used were shown, as expected.  If no parts were used on the workorder the subrptWoParts_Placeholder informed the end user of such.

Thank you for your advice!  I am now using this method on other complex reports as well.    

-Richard

0
 

Author Comment

by:roverturf
ID: 22782841
Thank you both for your assistance.

Jeff,  How did you incorporate your example jpg into your answer?

-Richard (roverturf)
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22793808
I simply attached the jpg image by clicking the "Attach File" button.

Or do you mean: How did I make the image?

JeffCoachman
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question