Lets start with the orphaned group header.
1. Make sure that your report is narrow enough to fit on your page. The grid
needs to be the width of paper minus the width of both margins.
2. Add a Group Footer to reference_last.
Click on the footer and in Properties, Format, choose Force New Page - After
Section (so that each group starts on a new page.
3.If you have any Page Break controls in your report, take them out for now.
I haven't experimented with them yet so I don't know if they make a
difference.
4. Click on the Page Footer bar (not the Group Footer) and in Properties,
Events, check if it says
Event Procedure next to On Format
If it doesn't, click next to On Format, Choose Event Procedure, click just
right of that and look at the first line of code which you see. If we have
it right, it will be the code which you pasted in. Otherwise, replace the
first line of our code (Private Sub PageFooterSection_Format(Cancel As
Integer, FormatCount As Integer)
with whatever you see there.
It could be different in different versions of Access.
Remember, CtrlGrpPages should have nothing written in it except by the code
(when we get it working!)
It should say Unbound when you are in Design View.
5. Is you report by any chance a Multi-column report? I've not experimented
with that so I don't know if it makes a difference.
I have to tell you that it took me quite a bit of fiddling before I got this
code working. I had Repeat Section set to Yes in my report (it should be No)
which mucked it up and then I didn't spot that the first line of code was in
a different format than in my version of Access.
Evi
I appreciate your patience, Evi. I'm pretty familiar with Access and
coding,
but this is taking me into new territory! fun!
I did everything you said to the "T", including pasting the code back in
from your reply (even though it was identical to what I already had
there).
I made the changes as needed.
My sorting group field is "reference_last". I hadn't added the group
header, and when I did, and put the reference_last control in it the first
page in the printout prints properly, but when the second group begins,
that
first page only has the group field at the top, with no detail. The
detail
part doesn't start until page 2. That's one "oddity" that's popped up.
Regarding the CtlGrpPages control in the page footer, it is blank. (I set
the control border to solid so I can see it, but it's empty.)
I get no errors when I shift to print preview. Just no "page x of y" in
the
footer, plus that one other oddity.
Any ideas for me?
Jerry
:
It's a fairly complex bit of coding. If you are new to this then you may
need to ask quite a few questions to get it right but don't give up.
Have you Grouped your report using the Sorting Grouping box and giving
it a Group Header? Put the control/field by which you want to group your
report into the group header (so if you are grouping by Salesman, put the
Salesman control there).
The Properties button is on your toolbar when you are in Report Design
View. If you aren't sure where it is, then you almost certainly haven't set
the Repeat Section
. You can also get at Properties by clicking on any
part of your report, right clicking, then choosing Properties from the list.
Click on that grey bar just above the Header section of your group with
the Properties box open, (the text in the colored area at the top of the
Properties box will say something like GroupHeader) click on the Format tab
and check that next to Repeat Section, it says No.
Going to View Code is the correct place to put your code.
Put a new text box in your report page footer. Click on the text box,
click on Properties, click on the Other tab and next to where it says Name,
type:
CtlGrpPages
(note the spelling is not ctrGrpPages)
(the Me bit is how a report refers to itself in the Code page - it's not
the name of the control)
Paste all this code over everything on your report's code page. I've
repeated it below (sorry about the HTML everyone) in the hope that it won't
break up the lines. Just check on the web page. Note that I've changed the
line that starts
Private Sub PageFooter
by adding the word Section. (the code didn't work in Access 2000 until I
did )
Where it says Me!Salesman you will need to edit the code.
If the field by which you have grouped is called say InvoiceNumber then
change that to
Me![InvoiceNumber]
(I've put square brackets around the field in case you have spaces or
symbols in your field name)
If it doesn't work, let us know what is happening ie you just can't see
your new text box at all, it doesn't have the right numbers in it, it
doesn't have anything in it) If a grey box appears warning of an error, tell
us what the error is. If it offers you the chance to Debug, press Debug and
let us know which line is highlighted.
(to get the report working again after pressing Debug, click Reset (the
small blue square) on the toolbar)
'************ Code Start *************
' This code was originally written by James H Brooks.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' James H Brooks
'
Option Compare Database
Option Explicit
Dim GrpArrayPage(), GrpArrayPages()
Dim GrpNameCurrent As Variant, GrpNamePrevious As Variant
Dim GrpPage As Integer, GrpPages As Integer
Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As
Integer)
Dim i As Integer
If Me.Pages = 0 Then
ReDim Preserve GrpArrayPage(Me.Page + 1)
ReDim Preserve GrpArrayPages(Me.Page + 1)
GrpNameCurrent = Me!Salesperson
If GrpNameCurrent = GrpNamePrevious Then
GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
GrpPages = GrpArrayPage(Me.Page)
For i = Me.Page - ((GrpPages) - 1) To Me.Page
GrpArrayPages(i) = GrpPages
Next i
Else
GrpPage = 1
GrpArrayPage(Me.Page) = GrpPage
GrpArrayPages(Me.Page) = GrpPage
End If
Else
Me!ctlGrpPages = "Group Page " & GrpArrayPage(Me.Page) & " of " &
GrpArrayPages(Me.Page)
End If
GrpNamePrevious = GrpNameCurrent
End Sub
'************ Code End *************
Evi
Thanks for the link, Evi. I'm trying to get it to work, but to no
avail at
the moment. Where do I find the properties setting you referenced
("Properties, you have set the group header or footer to Repeat
Section.")?
I thought I did as I should by placing the code under "View-->Code",
changing the reference to my group field name and placing
"Me!ctrGrpPages" in
a control in the page footer. However, when I go to print I get the
prompt
for "Me".
Any idea what I missed?
Jerry
:
http://www.mvps.org/access/reports/rpt0013.htm
has instructions how to do this. Note that it doesn't work if , in
Properties, you have set the group header or footer to Repeat
Section.
Evi
I've designed a 2-page report and I'd like to have "Page x of y"
printed
at
the bottom of each page. so, if I was running the report on 2
records it
would print 4 pages, with the first one printing "page 1 of 2" at
the
bottom,
the second page printing "page 2 of 2" and the third page printing
"page 1
of
2", etc.
How do I do that?