• forcing new page on header with VBA (Access03)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » forcing new page on header with VBA (Access03)

    Author
    Topic
    #422686

    I am trying with VBA to force a page break on a group if a control is not checked. The checkbox default setting is -1 forcing the user to manually change it for a run on report. I don’t get any error messages with this code but neither do I get the three departments to print on one page. Thank you for your assistance.

    Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
    Dim intGetVal As Integer

    If [Forms]![frmReports]![chkForceBreak] = -1 Then
    intGetVal = [Reports]![rptStaffListingByUnit].Section(acDetail).ForceNewPage = 1
    Else
    intGetVal = [Reports]![rptStaffListingByUnit].Section(acDetail).ForceNewPage = 0
    End If
    End Sub

    Fay

    Viewing 0 reply threads
    Author
    Replies
    • #964799

      A line such as

      intGetVal = [Reports]![rptStaffListingByUnit].Section(acDetail).ForceNewPage = 1

      doesn’t set the ForceNewPage property, it only compares its value to 1, and assigns the result (True if is 1, False otherwise) to intGetVal. So nothing happens. You only have to set the property once, when the report opens, so instead of the On Format event of GroupHeader0, I would use the On Open event of the report:

      Private Sub Report_Open(Cancel As Integer)
      Me.Section(acDetail).ForceNewPage = -[Forms]![frmReports]![chkForceBreak]
      End Sub

      Note that you can refer to the report as Me in its own module.

      • #964804

        Thank you Hans. This almost works it splits at the detail level and I need it to split at the GroupHeader0 level. I exchanged GroupHeader0 and acGroupHeader0 for acDetail, but those didn’t work. Fay

        • #964806

          If it’s the first group header, try acGroupLevel1Header; and if it’s the second group header, try acGroupLevel2Header.

          • #964807

            Thanks Hans level 1 did it. I had searched on GroupHeader not GroupLevelHeader. That kind on issues is that I thinks makes it complicated to get the job. But with yours and others help I am getting where I want to go. Thank you. Fay

    Viewing 0 reply threads
    Reply To: forcing new page on header with VBA (Access03)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: