I am trying to make a report for a proposal. I would like to keep a professional look and always force the terms section to the bottom of the page. I could use the page footer but I only want the terms to show on the last page.
My idea is somehow with VBA to set the height of a dummy group such that it forces the report footer to the bottom. The problem is that you can't explicitly set the height of a section.
Anyone else out there with another idea (That works)? :-)
Thanks, Jeff
Here's an idea:
http://bytes.com/topic/misc/answers/499733-report-footer-location-problem#post1939746
To accomodate single page reports you could do something like
If Me.Pages > 0 Then
Me.Section(4).Visible = (iif(Me.Pages = 1, True, Me.Page = Me.Pages))
EndIf
Note that Access only calculates the number of pages if you have page numbers on your report. If you don't want them displayed you can set their Visible property to False.
This did the trick for me:
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Me.PageFooterSection.Visible = (Me.txtPage <> Me.txtPages)
End Sub
Thanks for your help.
Related
I have a table in Access that has comments in one field and a file path to an associated picture in another. My report has the comment and then an image bound to the file path field underneath that comment. However, most comments do not have a picture with it, and the empty space between comments makes the report unnecessarily long.
Is there a way in VBA to only add an image control if there is a file path and minimize the spacing between the pictureless comments?
You can't add any controls to a report when Access is in Runtime mode. But you can easily resize the image control using VBA in one of the Report's Format methods. Assuming your Image control is named "Image1", and it is in the Detail section:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Image1.ImageHeight = 0 Then
Me.Image1.Height = 144 ' whatever minimum height you want
Me.Detail.Height = 144
Else
Me.Image1.Height = 1440 ' whatever the normal Image1 height is
Me.Detail.Height = 1530 ' whatever maximum detail height you want
Endif
End Sub
That should be very close to what you need.
Is there any way to hide a group footer based on a piece of information in the group header or detail? I only want to hide it for some records, not the entire report.
For instance, if I have a report of media types, I want to show a disclaimer "*Melts after prolonged exposure to sunlight" in the footer of any vinyl records, but not in the footer for compact disks.
I put an if-then into the GroupHeader_Format event like this:
If media_type = "vinyl" Then
GroupFooter.Visible = True
Else
GroupFooter.Visible = False
End If
In a subreport I created a sub on detail_format event that will display a text when there is no data returned.
‘Code in sub-report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Report.HasData Then
Me.Label43.Visible = True
Me.txtNotEntered.Visible = False
Else
Me.Label43.Visible = True
Me.txtNotEntered.Visible = True
End If
End Sub
It works fine on the subreport when run alone. When I run the main report it doesn’t trigger.
I added the same code in the main report to see if it would work. It runs through the lines of code but still cannot see the txtNotEntered textbox control.
‘Code in main report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me!rptResults_Comments.Report.HasData Then
Me!rptResults_Comments.Report.Label43.Visible = True
Me!rptResults_Comments.Report.txtNotEntered.Visible = False
Else
Me!rptResults_Comments.Visible = True
Me!rptResults_Comments.Report.Label43.Visible = True
Me!rptResults_Comments.Report.txtNotEntered.Visible = True
End If
End sub
I am using MS Access 2003.
Since the subreport is bound to the main report, the subreport itself will not be shown if there is no data to connect it to the main report. You can see this better by setting the background color of the subreport's detail section to red, or any other non-white color.
One workaround is to move your txtNotEntered control to the main report and put it "under" the subreport control (using Send to Back). Then set your subreport control's Can Shrink property to True.
Then, when there is data in the subreport you will see the subreport and it will cover the txtNotEntered control. When there is no data, the subreport will shrink out of the way and you will be able to see the txtNotEntered control.
One advantage to this approach is that it requires no code. Just leave the txtNotEntered Visible property set to True. The shrinking of the subreport will take care of revealing it when appropriate.
In addition to the answer from mwolfe02, I would suggest instead of using a label and VB code use a textbox with the following expression:
=IIf([HasData],"","No data found")
I use this on all my reports. An expression like
=IIf([rptResults_Comments].[Report].[HasData],","No data found")
should work as well. I didn't test the latter expression, so I'm not sure if [Report] is needed or not.
In addition to #rick's problem, how to display "No data" text when a subreport has No Data, it is also common enough to want to handle the case where main report controls reference subreport controls (and the subreport(s) has(have) No Data). This might occur when you are calculating a total that references subtotals from many subreports.
So we can put together #mwolfe02's and #TheOtherTimDuncan solutions (repurposing from #TheOtherTimDuncan his use of the HasData property), with some incidental additions of my own, as a checklist.
We have a main report rptMain and a subreport srpSub. In rptMain, detail section, we have a subcontrol sbctSub which references srpSub.
On rptMain create a label (there's no general need for it to be a textbox) lblNoData with whatever text you like (e.g. "No Data Returned"). Place lblNoData under sbctSub (using Send to Back). Use the same Top value. This ensures these don't overlap vertically so problems don't occur when Shrinking/Growing occurs.
Add an "annotating" label that is always viewable by a developer in design view but is permanently set to Visible = No (which makes it invisible in non-design views) with text like "Hidden lblNoData under subcontrol". If this needs to shrink (Can Shrink = Yes) then make it an unbound textbox. Colour such an annotating label (or textbox) to stand out in design view (e.g. I generally use a blue). Otherwise, down the track, there's a danger of losing sight, as a developer, of what's going on (worse still if another developer has to analyze your work).
Ensure the following are set to Can Shrink = Yes:
rptMain, Detail.
sbctSub.
When srpSub has no data then lblNoData will be revealed to the user as sbctSub will have shrunk to zero.
In production there might be issues with the No Data label showing through (white backgrounds seem to act transparently in some circumstances). If so, in rptMain:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.lblNoData.Visible = (Not Me.sbctSub.Report.HasData)
End Sub
(My "design spike" testing worked as #mwolfe02 mentioned. That is, no additional code was necessary and I could rely on the subcontrol to hide and reveal the No Data label as needed. However my production report had these weird transparency issues.)
If you have any control on rptMain (e.g. txtGrandTotal) that references a control on srpSub, then set the control source as follows
=IIf([sbctTemp].[Report].[HasData],[sbctTemp].[Report]![txtSubTotal],0)
Null to zero Nz() won't work where the referenced control doesn't even exist, due to the subreport returning no data.
Edit 01: Added additional code to hide and show the No Data label in case of transparency issues. Rearranged this from being listed the last step, to being listed more sensibly in the order.
Edit 02: Made mention that the annotating label should be a textbox if it needs to shrink.
I want to use Globals!PageNumber in Report body part. How can I access inside Report body?
I am using SQL Server Reporting Service 2008 R2.
Create functions in the code under the report properties:
Page Number:
Function PageNumber() As String
Return Me.Report.Globals!PageNumber
End Function
Total Pages:
Function TotalPages() As String
Return Me.Report.Globals!TotalPages
End Function
Access it in the body via an expression:
=code.PageNumber & " of " & code.TotalPages
Check out Sample Usage of the Concat Function
Unfortunately in Reporting Services (up to RS2008), this will produce "Page 1 of 1" on every page. The problem is that the body is rendered before the header and footer, therefore the code cannot access the correct pagination, since it is determined AFTER all elements in the body.
If your report is basically a large table with predefined number of rows on each table, try using row_number in your SQL as a workaround to manually calculate page numbers: http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/c2047eee-41a8-4d79-ae58-dbf60f6e7554/
you can't use page number in body. use it only in report footer or header.
For that you need to use Report variables:
Go to Report Menu from main Menu in Visual Studio, > Click on Report Properties > Add new variable - named as PageCount (Default value to 0)
Then inside header of footer create one textbox and set below expression,
=Variables!PageCount.SetValue(Variables!PageCount.Value+1)
It will automatically increase for each page.
NOTE: Do not hide it from header or footer, the SetValue will not work if you hide the box, so change the font of textbox to white color. (Do whatever you want but just do not hide it. Then you can use below expression to fetch pagenumber value inside report body.
=Variables!PageCount.Value
I have taken reference from this answer.
I'm stuck with the following:
I have an Access2003 report "rptInvoices".
Group levels are on CustomerID and PackingListID.
What I like to achieve is that every 2nd (or 3rd etc.) page of an invoice starts with a blank section (of say 9cm) at the top of the page. For this I would use an empty PageHeader section. If the Report's property PageHeader had a value like NotWithGroupHeaderX, this would be easy.
Since there isn't such a value: how can I hide the PageHeader on a report if there's a GroupHeader named grhCustomerID on that page?
Maybe I need a different approach, but I just don't see it.
In the groupheader format event set the pageheadersection.visible to true so the page header prints for pages after the group header. In the group footer format event set the pageheadersection.visible to false so the page header does not print at the top of the next page which has the group header.
You can set the visible property of the page header in the format event of the group header.
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
Me.PageHeaderSection.Visible = False
End Sub
Private Sub Report_Page()
Me.PageHeaderSection.Visible = True
End Sub