Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a conditional page break using event procedure 1

Status
Not open for further replies.

Minimorgie

Technical User
Feb 14, 2005
29
GB
Hi,

I posted this in the VBA forum but have been pointed to this one so hopefully someone can help me.

I'm producing a duplex report in Access 2003, on the reverse page are diary comments which sometimes go over one page, this throws what should be the front page onto the back page. The diary comments are inserted via a sub-report. In the main report I'm trying to create a conditional page break using VB. I've inserted the page break and called it CondPgBreak and in the page header section have set the following so that a break does not always happen :

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Me![CondPgBreak].Visible = False
End Sub

In the footer I want to set a page throw wherever the page number is not odd, what should I put in the following where I have inserted the ???? :

Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
If (Me.Page ????????) Then
Me![CondPgBreak].Visible = True
End If
End Sub

OR am I going about this in totally the wrong way?

Any help would be much appreciated.
 
You can use Mod

[tt]If Me.Page Mod 2>0 Then
'Odd page[/tt]
 
Hi Remou,

Thanks for the advice, I tried it and I didn't get an error but infortunately I didn't get a page break either. I need the page throw where the 'front sheet' does not appear on an odd numbered page so I changed the code to read
If Me.Page Mod 2 = 0 which is hopefully correct because I want the page throw on even numbered pages.

I've tried inserting this code in the footer section and the detail section but neither has the desired effect.

Any further help would be gratefully received!!

Thanks
 
How have you set this up? Like this?

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    If Me.Page Mod 2 > 0 Then
        Me.PageBreakX.Visible = False
    Else
        Me.PageBreakX.Visible = True
    End If
End Sub
 
Hi Remou,

That's done the trick - thank you very much for your help. I think the problem was due to the fact that in the page header section I had set condpgbreak to visible = false and this appeared to override what was in the detail section. Having the condition and then the page break visible = true or false together in the detail section and removing it from the page header section made it work. I can now breath a sigh of relief!
 
Hi Remou,

Oh dear I've just noticed that my pagination has gone wrong as a result of this conditional page break. My report now shows Page x of 16 but in total there are only 12 pages. Any ideas why and how to resolve this. I've tried putting the pagination at the top of each page instead of the bottom but this doesn't make any difference.

Thanks
 
Hi - I've sorted this out myself, the problem seemed to be with the code being in the detail_print section, I've moved it to the detail_format section and this seems to have sorted out the incorrect pagination and retained the page break in the correct place.

Sorry for the unecessary post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top