Flip headers/page numbers

  • Thread starter Thread starter Joseph Greenberg
  • Start date Start date
J

Joseph Greenberg

I have a report that will print two-sided. I want to shift the binding
margin from left to right, and I have a header that has some static text on
the left and the page number on the right. I'd like each page to have the
static text on the "inside" and the page number on the "outside" - so the
two text boxes have to "flip". Any ideas how this can be done? My report is
text fields in some group headers, followed by child records in the detail
section. There is also a line separating whole "families".
 
Easiest way that I can think of is to have two sets of controls stacked on top
of each other. So
txtPage1 and txtStatic1 would be stacked on the left side and txtPage2 and
txtStatic2 would be stacked on the right side.

Your code would alternate turning one set visible and the other invisible.

txtPage1.Visible = Me.Page Mod 2 = 1
txtPage2.Visible = Me.Page Mod 2 =0
txtStatic1.Visible = Me.Page Mod 2 = 0
txtStatic2.Visible = Me.Page Mod 2 = 1

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Joseph said:
I have a report that will print two-sided. I want to shift the binding
margin from left to right, and I have a header that has some static text on
the left and the page number on the right. I'd like each page to have the
static text on the "inside" and the page number on the "outside" - so the
two text boxes have to "flip". Any ideas how this can be done? My report is
text fields in some group headers, followed by child records in the detail
section. There is also a line separating whole "families".


Kind of messy, but more tedious than complex. The idea is
to adjust the Left property of every control. On odd pages
add your binding margin difference to every control's Left
property and subtract it on even pages.

The adjustment would be different for the two controls in
the page header.


First drag all of the controls to the desired position on
*even* pages.

Then a rough idea of the kind of code in the page header
section Format event might be somethng like:

Const BindMargin As Long = .5 * 1440 ' 1/2 inch
Dim ctl as Control

For Each ctl In Me.Controls
ctl.Left = ctl.Left + IIf(Me.Page Mod 2, 1, -BindMargin,
BindMargin)
Next ctl

If Me.Page Mod 2 Then
Me.txtStatic.Left = Me.Width - Me.txtStatic.Width
Me.txtStatic.TextAlign = 3 'right align
Me.txtPageNum.Left = 0
Me.txtPageNum.TextAlign = 1 'left align
Else
Me.txtStatic.Left = 0
Me.txtStatic.TextAlign = 1 'left align
Me.txtPageNum.Left = Me.Width - Me.txtPageNum.Width
Me.txtPageNum.TextAlign = 3 'right align
End If
 
I tried using code like this, particularly the bit that loops through and
moves each control, but it never got past the first control, it gave me an
error of the nature that it would be outside the legit area. I ended up
making it work by manipulating the printer object:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
If Me.Page = 1 Then
MoveMargin = 360
ElseIf Me.Page Mod 2 = 0 Then
MoveMargin = -360
Else
MoveMargin = 360
End If
ChangeMargins
End Sub

Public Sub ChangeMargins()
Printer.LeftMargin = Printer.LeftMargin + MoveMargin
If Me.Page = 1 Then Exit Sub
If Me.Page Mod 2 = 0 Then
With lblPageHeader
.TextAlign = 3
.Left = 4140
End With
With txtPageNumber
.TextAlign = 1
.Left = 0
End With
Else
With lblPageHeader
.TextAlign = 1
.Left = 0
End With
With txtPageNumber
.TextAlign = 3
.Left = 4140
End With
End If
End Sub

Is this inefficient? What are the implications of using the printer object
instead of maniulating the controls?

I will say that when I close the report, it take a good few seconds to
bounce through all the events, there seems to be some crazy loop which I
can't figure out. Any ideas on that? Does close trigger the format event?
 
Joseph said:
I tried using code like this, particularly the bit that loops through and
moves each control, but it never got past the first control, it gave me an
error of the nature that it would be outside the legit area. I ended up
making it work by manipulating the printer object:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
If Me.Page = 1 Then
MoveMargin = 360
ElseIf Me.Page Mod 2 = 0 Then
MoveMargin = -360
Else
MoveMargin = 360
End If
ChangeMargins
End Sub

Public Sub ChangeMargins()
Printer.LeftMargin = Printer.LeftMargin + MoveMargin
If Me.Page = 1 Then Exit Sub
If Me.Page Mod 2 = 0 Then
With lblPageHeader
.TextAlign = 3
.Left = 4140
End With
With txtPageNumber
.TextAlign = 1
.Left = 0
End With
Else
With lblPageHeader
.TextAlign = 1
.Left = 0
End With
With txtPageNumber
.TextAlign = 3
.Left = 4140
End With
End If
End Sub

Is this inefficient? What are the implications of using the printer object
instead of maniulating the controls?

I will say that when I close the report, it take a good few seconds to
bounce through all the events, there seems to be some crazy loop which I
can't figure out. Any ideas on that? Does close trigger the format event?


I have not used the Printer Object enough to be familiar
with its nuances so I can't answer your question about the
implications. That said, if it works ...

I would not expect(?) closing the report to trigger any
events beyond the Close event. BUT, that's not to say there
isn't anything (including bugs) that don't do strange
things, especially if you just switch to design view. I
have heard of a bug in some versions of Access where closing
a form causes a requery of some things like a combo box's
row source query, but I have not heard of something similar
in reports.
 
Back
Top