Access Report PageHeader not with GroupHeader - ms-access

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

Related

Dynamically add image controls on Access report

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.

Set focus to specific field in Access 2010

How do I set the focus on a particular field (in this case, the "Ref:" field which is located in the Form Header) when viewing a form in Form View?
You could use SetFocus in Form_Active
Private Sub Form_Activate()
yourField.SetFocus
End Sub
or you could change the order tab and put your field into first place of the list

Access Report Detail Format - Default Values and Referencing

This question is mainly for curiosity, but also, in the description, I had intended to highlight an infrequently documented behavior of Access.
Background
When creating an Access report, we can use the On Format method of the detail section to modify values or properties per-record. For example, assume we want to hide a field label when the value is empty:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If (IsNull(Me.SomeField) Or Me.SomeField = "") Then
Me.SomeFieldLabel.Visible = False
Else
Me.SomeFieldLabel.Visible = True
End If
End Sub
What I did not realize about this until today is that the assignment .Visible = False does not modify the instance of the label in the Detail section, but rather is modifying the definition of the label on the report.
This can be demonstrated with the following modifiction to the code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If (IsNull(Me.SomeField) Or Me.SomeField = "") Then
Me.SomeFieldLabel.Visible = False
End If
End Sub
Assuming the label is initially visible (in form Designer), the event produces somewhat unexpected behavior: the label will remain visible until the first empty record; after that, it will remain hidden for all other records - I had originally expected that at each call of Detail_Format the controls where starting with their default definitions.
Question
Is there any way to reference the particular instance of a control within the Detail_Format event?
In this simple case of visible true/false, this is easily handled by just a simple if-then-else, but I can imagine more advanced scenarios where one might want to leave the default values in tact.
I don't believe so, in all of my experience, properties of report objects always apply universally across the report, not to specific instances of the abject (if the object is repeated).
For your example, I would use a text box instead of a label to label the field, and use something like =IIf(IsNull(Field1), "", "Label:") for the controlsource. That way it won't show anything if the field is null, yet still show the label text if there is a value.

Access: Display Textbox Control In Sub-report when it has No Data

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.

MS Access Force report footer to bottom of page

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.