473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Setting subreport visibility in Report

2 2Bits
Hello all

I have an Access 365 report that contains 3 subreports. I would like to make one of the subreports visible, only if it contains data.

My plan was to use a control that contains a count of records in this subreport. If that count is zero, then set visibility of the subreport to false.

The subreport is called "NegConsentOutputAccounts_subreport"
The control with the record count is "text45" in the main report (placeholder while I work this out)

I thought I could get away with something as simple as:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.     If Me.Text45 = 0 Then
  3.         Me.NegConsentOutputAnnuity_subreport.Visible = False
  4.     Else
  5.         Me.NegConsentOutputAnnuity_subreport.Visible = True
  6.     End If
  7. End Sub
But apparently not. Triggering the report yields no visible action. No error message. Removing/commenting the code and the report is generated as expected.

I verified that the text45 control is variable. I get the same non-result whether the value is zero or non-zero.

Thanks in advance for any assistance.

SC
Apr 28 '21 #1

✓ answered by twinnyfo

enilc,

Welcome to Bytes!

First, in order for such code to work, it would need to be placed in the OnFormat Event of the Report's section that contains the sub-report.

However, a much more easier way to do this is to have the height of the subreport set to 0, and have the subreport's CanGrow property set to yes. Thus, when there are records, the subreport will expand to show them; when there are no records, the report "disappears."

Please let me know if you have additional questions about implementing this.

Hope this hepps!

6 2703
twinnyfo
3,653 Expert Mod 2GB
enilc,

Welcome to Bytes!

First, in order for such code to work, it would need to be placed in the OnFormat Event of the Report's section that contains the sub-report.

However, a much more easier way to do this is to have the height of the subreport set to 0, and have the subreport's CanGrow property set to yes. Thus, when there are records, the subreport will expand to show them; when there are no records, the report "disappears."

Please let me know if you have additional questions about implementing this.

Hope this hepps!
Apr 28 '21 #2
NeoPa
32,556 Expert Mod 16PB
Hi.

I suspect that you're trying to use the value before it's been properly populated. The Open event triggers before the data is prepared. The Activate event, and be warned this can occur multiple times for the same report instance so code to run once needs to be wary of this, occurs after the Open event and may well be what you need. Give it a try maybe.
Apr 28 '21 #3
NeoPa
32,556 Expert Mod 16PB
Also you can simplify the code somewhat to make it less clumsy :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Activate()
  2.     With Me
  3.         .NegConsentOutputAnnuity_subreport.Visible = (.Text45 <> 0)
  4.     End With
  5. End Sub
This won't be a problem if run multiple times so there's no real need to ensure it only runs once.

PS. Having now managed to see Twinny's suggestion I would reccomend trying that first. We both posted when the thread was still in the moderation queue so both our replies went there too. I've released all now.

If his approach works for you then it's even more elegant than having to write code. Why write code for something already handled perfectly well by Access naturally?
Apr 28 '21 #4
enilc
2 2Bits
These responses have all been extremely helpful, both for this issue and some others.

However, after much trial and error I found something...quirky

I had the subreport set to grow/shrink. I had the subreport set to 0 height. And regardless the countless iterations of my previous code, the header and column headers would still appear on the master report, with no data.

I saw mentioned in several places that a subreport with no data should not appear on the master report, but that was not the case in this situation.

Finally, on a whim, I switched the report to "Print Preview" and the subreport was entirely not visible. I went back to "Report View" and the empty subreport was again, not visible.

So, what I found is that when a report is opened initially in report view, a subreport with zero records will appear in the report. It doesn't go to "not visible" until the view is changed to "Print Preview"

It's an odd functionality that I don't understand, but one I can live with.

@Twinnyfo: I hadn't seen the onformat event, but have other plans for that now. With regard to the second part of your post: as mentioned above, the subreport won't "disappear" (like I desire) until I go in-out of Print Preview for some reason.

@NeoPa: I've not used that format for code before, but I like the brevity and will use it in the future.

Thanks again for your quick and very helpful responses.
SC
Apr 29 '21 #5
twinnyfo
3,653 Expert Mod 2GB
SC,

Also as a side note, concerning Report View (and layout View), I have all my reports default view set as "Print Preview" and I have the "Allow Report View" and "Allow Layout View" set to "No." This always ensures that when you are designing and testing your reports that "what you see is what you get." There can be some useful features of Layout View, but I prefer to make all my design and layout changes in Design view. I can control things a bit better there. Much of this all comes down to preference.

Let us know if you come across any other sticklers--we'll be glad to hepp!
Apr 29 '21 #6
NeoPa
32,556 Expert Mod 16PB
As Twinny says, Print Preview is what you're interested in. I suggest you read up on what the others are provided for. It's not something you're likely to be interested in. Essentially Print Preview shows you what you would get were you to print it.

In my view anything else is pointless, but people have their weird and wonderful requirements. All you need to worry about is understanding what you actually want. That way you use Design View & Print Preview and the other options never get in your way.

PS. I echo Twinny's invitation to come back and post more questions when you need. We look forward to helping where we can.
Apr 30 '21 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: dixie | last post by:
I have a report with a subreport. The source object for this subreport varies according to the value of a field in a table. I am trying to programmatically set the object source for the subreport...
3
by: CSDunn | last post by:
Hello, I currently have an Access 2003 ADP Report/Subreport set up in which I have 12 subreports in a single main report that are located in a group header called 'PermnumHeader' (Permnum would be...
4
by: Mark Reed | last post by:
Hi Guru's, Hopefully I can explain this OK.....What I am trying to do is create a QC check sheet using the following fields: ASN, PO & Qty. This information will be at the top of each report with...
7
by: Ellen Manning | last post by:
I've got an A2K report showing students and their costs. Student info is in the main report and costs are in a subreport for each student. The user inputs the program desired then only those...
4
by: Trevor Best | last post by:
I have a report that's fairly simple, page headers and footers, detail has a subreport in (can vary in length). The customer wanted a signature block for them, their client and 3rd party. This was...
0
by: Hrcko | last post by:
I put an exiting subReport into Main report, but when I want to open it I get an error message: Failed to open connection. Should I open somehow subReport as a different report in Main report?...
2
by: Mike.Wolowicz | last post by:
I have a report that changes background colour when a running total field hits a certain value... Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) If >= 2400001 Then...
11
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Master Report is: Me.RowSource = "TableOrQueryName"
2
by: gigiot | last post by:
I have a problem when try to add a SubReport to a report. I'm using Visual Studio 2010. I've two report and two DataSet, one of every report. I've created master-report (report1) and i've added a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.