By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,396 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,396 IT Pros & Developers. It's quick & easy.

forcing a page break in a report using code?

P: n/a
Hello,

I'm looking for a way to force a pagebreak in code. I'm having a tough
time, the first page formats properly until the condition is met and then
forces a new page. The problem is, every page after that forces a new page
after a single record. I'm trying to force the page after 12 records. The
code is pretty simple. I have a footer called "BreakFooter" that i have
associated with the ID field, so each detail record is unique. For
simplicity's sake, I've replaced the variable with hard coded numbers;

If MoveCount >= 12 Then
BreakFooter.ForceNewPage = 2
Else
BreakFooter.ForceNewPage = 0
End If

Most of the searches I get return information on how to force a page break
using Grouping and Sorting, but no code really.

Any help would be great.

Thanks!
May 12 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Fri, 12 May 2006 03:18:55 GMT, Rico wrote:
Hello,

I'm looking for a way to force a pagebreak in code. I'm having a tough
time, the first page formats properly until the condition is met and then
forces a new page. The problem is, every page after that forces a new page
after a single record. I'm trying to force the page after 12 records. The
code is pretty simple. I have a footer called "BreakFooter" that i have
associated with the ID field, so each detail record is unique. For
simplicity's sake, I've replaced the variable with hard coded numbers;

If MoveCount >= 12 Then
BreakFooter.ForceNewPage = 2
Else
BreakFooter.ForceNewPage = 0
End If

Most of the searches I get return information on how to force a page break
using Grouping and Sorting, but no code really.

Any help would be great.

Thanks!


That's what your code is telling it to do.

What is MoveCount? A Counter control in the Detail section?
Try:
If [MoveCount] Mod 12 = 0 Then
BreakFooter.ForceNewPage = 2
Else
BreakFooter.ForceNewPage = 0
End If

I would have simply added a PageBreak control to the detail section.
Code the Detail Format event:
Me![PageBreakName].Visible = Me![MoveCount] Mod 12 = 0

It would force a page break after each 12 records.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
May 12 '06 #2

P: n/a
Hi Fred,

Sorry about that, the MoveCount is a variable that increments by 1 every
detail line and then resets back to 0 when the page header formats.

I tried doing the pagebreak visible thing, but still have the same result.

Here's all the report code so you can see everything that's going on;

Dim MoveCount As Integer
Dim LastMoveCount As Integer
Private Const intLineCnt As Integer = 12 'CalcLinesToMove()

Private Sub BreakFooter_Format(Cancel As Integer, FormatCount As Integer)

End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.MoveLayout = True
Me![PageBreakName].Visible = (MoveCount Mod 12 = 0)

If MoveCount < intLineCnt Then
Me.NextRecord = False
' Me.MoveLayout = True
'Me.PrintSection = False
MoveCount = MoveCount + 1

Else

Me.NextRecord = True
' Detail.ForceNewPage = 2
' Me.MoveLayout = True
'Me.PrintSection = True
End If
Exit Sub

End Sub

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
MoveCount = 0
PageBreakName.Visible = False
'Detail.ForceNewPage = 0
'Detail.ForceNewPage = 0
End Sub

Private Sub PageHeaderSection_Print(Cancel As Integer, PrintCount As
Integer)
Me![PageBreakName].Visible = False '(MoveCount Mod 12 = 0)
End Sub
It's driving me nuts at this point, this shouldn't be that hard! ;)


"fredg" <fg******@example.invalid> wrote in message
news:tw****************************@40tude.net...
On Fri, 12 May 2006 03:18:55 GMT, Rico wrote:
Hello,

I'm looking for a way to force a pagebreak in code. I'm having a tough
time, the first page formats properly until the condition is met and then
forces a new page. The problem is, every page after that forces a new
page
after a single record. I'm trying to force the page after 12 records.
The
code is pretty simple. I have a footer called "BreakFooter" that i have
associated with the ID field, so each detail record is unique. For
simplicity's sake, I've replaced the variable with hard coded numbers;

If MoveCount >= 12 Then
BreakFooter.ForceNewPage = 2
Else
BreakFooter.ForceNewPage = 0
End If

Most of the searches I get return information on how to force a page
break
using Grouping and Sorting, but no code really.

Any help would be great.

Thanks!


That's what your code is telling it to do.

What is MoveCount? A Counter control in the Detail section?
Try:
If [MoveCount] Mod 12 = 0 Then
BreakFooter.ForceNewPage = 2
Else
BreakFooter.ForceNewPage = 0
End If

I would have simply added a PageBreak control to the detail section.
Code the Detail Format event:
Me![PageBreakName].Visible = Me![MoveCount] Mod 12 = 0

It would force a page break after each 12 records.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

May 12 '06 #3

P: n/a
Report Section Events are pretty arcane.
Have you tested to ensure that this line
MoveCount = 0
is actually executed each time you think that it is executed?
Have you considered removing that line and using
MoveCount Mod IntLineCount = IntLineCount - 1 as your test statement?

May 12 '06 #4

P: n/a
On Fri, 12 May 2006 04:13:41 GMT, Rico wrote:
Hi Fred,

Sorry about that, the MoveCount is a variable that increments by 1 every
detail line and then resets back to 0 when the page header formats.

I tried doing the pagebreak visible thing, but still have the same result.

Here's all the report code so you can see everything that's going on;

Dim MoveCount As Integer
Dim LastMoveCount As Integer
Private Const intLineCnt As Integer = 12 'CalcLinesToMove()

Private Sub BreakFooter_Format(Cancel As Integer, FormatCount As Integer)

End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.MoveLayout = True
Me![PageBreakName].Visible = (MoveCount Mod 12 = 0)

If MoveCount < intLineCnt Then
Me.NextRecord = False
' Me.MoveLayout = True
'Me.PrintSection = False
MoveCount = MoveCount + 1

Else

Me.NextRecord = True
' Detail.ForceNewPage = 2
' Me.MoveLayout = True
'Me.PrintSection = True
End If
Exit Sub

End Sub

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
MoveCount = 0
PageBreakName.Visible = False
'Detail.ForceNewPage = 0
'Detail.ForceNewPage = 0
End Sub

Private Sub PageHeaderSection_Print(Cancel As Integer, PrintCount As
Integer)
Me![PageBreakName].Visible = False '(MoveCount Mod 12 = 0)
End Sub

It's driving me nuts at this point, this shouldn't be that hard! ;)

"fredg" <fg******@example.invalid> wrote in message
news:tw****************************@40tude.net...
On Fri, 12 May 2006 03:18:55 GMT, Rico wrote:
Hello,

I'm looking for a way to force a pagebreak in code. I'm having a tough
time, the first page formats properly until the condition is met and then
forces a new page. The problem is, every page after that forces a new
page
after a single record. I'm trying to force the page after 12 records.
The
code is pretty simple. I have a footer called "BreakFooter" that i have
associated with the ID field, so each detail record is unique. For
simplicity's sake, I've replaced the variable with hard coded numbers;

If MoveCount >= 12 Then
BreakFooter.ForceNewPage = 2
Else
BreakFooter.ForceNewPage = 0
End If

Most of the searches I get return information on how to force a page
break
using Grouping and Sorting, but no code really.

Any help would be great.

Thanks!


That's what your code is telling it to do.

What is MoveCount? A Counter control in the Detail section?
Try:
If [MoveCount] Mod 12 = 0 Then
BreakFooter.ForceNewPage = 2
Else
BreakFooter.ForceNewPage = 0
End If

I would have simply added a PageBreak control to the detail section.
Code the Detail Format event:
Me![PageBreakName].Visible = Me![MoveCount] Mod 12 = 0

It would force a page break after each 12 records.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail


That's what I suspected. It's not a control. You're attempting to
count in the Format event.
The Format event can fire more than once as Access attempts to format
the page.

Do it differently.
No need for a special Group to force the page to break.

Add an unbound control to the Detail Section.
Set it's Control source to
=1
Set it's Running Sum property to
Over All (or Over Group, which ever is appropriate).
Name this control "RecCount".
You can make it not visible.

Add the PageBreak to the Detail Section.
Name the Page Break "MyBreak".
Code the Detail Format event:

[MyBreak].Visible = RecCount Mod 12 = 0
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
May 12 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.