Results 1 to 9 of 9
  1. #1
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178

    Unanswered: ForceNewPage doesn't always force?

    I have the following code in the report's Detail section:

    Code:
        If Me.Text16 = PrevTN Then
            ForceNewPage = 0
        Else
            If PrevTN = " " Then
                PrevTN = Me.Text16
                ForceNewPage = 0
            Else
                PrevTN = Me.Text16
                ForceNewPage = 1
            End If
        End If
    PrevTN is initialized to " " in the report's Open event. Running through the code in interactive mode (debug mode?) the settings of ForceNewPage work the way I want them to. However, the line ForceNewPage = 1 doesn't force Access to print the section on a new page. Am I doing something wrong?

    Please help.

    Thank you,

    Sam

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Just to tidy up your existing code:
    Code:
    Dim PrevTN As String
    PrevTN = ""
    
        If Me.Text16 = PrevTN Then
            ForceNewPage = 0
        Else
                If IsNull(PrevTN) Then
                    ForceNewPage = 0
                Else
                    ForceNewPage = 1
                End If
            PrevTN = Me.Text16
        End If
    I'm assuming that PrevTN may or may not be assigned a value before arriving at this point?
    George
    Home | Blog

  3. #3
    Join Date
    Feb 2007
    Posts
    16
    Hello Sam,

    I have created a small table with the following data:
    ID/text
    1/a
    2/b
    3/c
    4/d

    I wrote the following code for the report created from the table. It is very similar, just simpler as yours.

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.Test = "c" Then
    Detail.ForceNewPage = 1
    Else
    Detail.ForceNewPage = 0
    End If
    End Sub

    The fourth record (ID:4, text:d) is printed on a new page.

    In my understanding you want to print the letter "c" onto a new page. But when you check the value of the text box, it is already on the report, so only the next record (letter "d") will be printed on a new page.

    So you have to check the value BEFORE it is placed onto the report

    Axel

  4. #4
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    So you have to check the value BEFORE it is placed onto the report

    Axel
    How do I do that, Axel?

    By the way, George/Axel, I realize I didn't give away much info when I posted the question. The detail section is very large; only two records can fit on a page. Multiple records can have the same Text16. I want Access to change pages every time a new Text16 appears. I need to initialize the PrevTN in the report's Open event because I can only test for change if I do it that way. To initialize the variable every time I print the Detail section, Access will ALWAYS find a new number (Text16 is never blank), which is incorrect.

    In this case, there are two discrete Text16s, one for the first 3 records, and one for the last 2 records. Since 2 records print on a page - and the fourth record is where I need to detect the change before printring it - neither the Page Header section nor the Page Footer has access to the fourth record before printing.

    So, what do I do to force that record on a new page?

    Thanks to you both for writing.

    Sam

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Fancy posting a cut down/compacted/zipped etc version of the necessaries on here - I think this one requires a play to understand best!
    George
    Home | Blog

  6. #6
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Quote Originally Posted by georgev
    Fancy posting a cut down/compacted/zipped etc version of the necessaries on here - I think this one requires a play to understand best!
    I'll take you up on that, George. Thanks for the offer.

    Sam
    Attached Files Attached Files

  7. #7
    Join Date
    Feb 2007
    Posts
    16
    Hello Sam,

    Use this code, it does exatcly what you want:

    If Me.Text16 = PrevTN Then
    ForceNewPage = 0
    Me.NextRecord = True
    Me.PrintSection = True
    Else
    If PrevTN = " " Then
    PrevTN = Me.Text16
    ForceNewPage = 0
    Me.NextRecord = True
    Me.PrintSection = True
    Else
    Me.NextRecord = False
    Me.PrintSection = False
    PrevTN = Me.Text16
    ForceNewPage = 1
    End If
    End If

    Good luck!
    Axel

  8. #8
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    I'll have to try that when I get to work tomorrow. Thanks, Axel.

    The only drawback - in my mind, not in reality - is that I haven't been particularly successful with OnFormat() events in the past, so this may turn into a bit of a challenge. Also, as I never even heard of this property before, much less used it, I may have to play with it before I really understand how and when to use it.

    Sam

  9. #9
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Axel,

    I made a copy and paste into the OnFormat event, where it didn't work. I deleted it from there and put it into the OnPrint event, where it did work. Wierd. Because the NextRecord property and the PrintSection method are only supposed to work in the OnFormat event according to the help file. In any event it works, so I'll put it into my regular program.

    Thanks so much,

    Sam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •