Page Numbering Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhughes2187
    New Member
    • Mar 2008
    • 32

    Page Numbering Function

    I am trying to sequentially place page numbers across multiple reports.
    Basically what I am trying to do is on the first report, which has 3 pages, the first page is page one...after cycling through the pages and then closing the report, the next report opens and the page number starts at 4.

    I found an example of this, but when I try and incorporate it, it counts each line on the page as a page so instead of saying Page 1, it says Page 25 (the number of lines on the page is 24). I cannot figure it out.

    Code:
    (pagenumberfunctions)
    
    Option Compare Database
    
    Dim PageNumber As Integer
    Sub initPageNums()
     PageNumber = 0
    End Sub
    Function GetPageNumbers() As Integer
     PageNumber = PageNumber + 1
     GetPageNumbers = PageNumber
    End Function
    That is my code in a module called pagenumberfunct ions.

    On the first report, on open, I call initPageNums as an event.
    I then have an unbound text box in the page footer that has a control source of
    =GetPageNumbers ()

    But like I said it displays 25 instead of 1, 25 being the number of lines on the page + 1. Why would it count each line as a seperate page?
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hi, there.

    I guess it calls the function each time it formats a record.
    Would it be more reliable if your VBA function will return the first page number only and then in report control it will be added to current page number?

    Regards,
    Fish

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by bhughes2187
      I am trying to sequentially place page numbers across multiple reports.
      Basically what I am trying to do is on the first report, which has 3 pages, the first page is page one...after cycling through the pages and then closing the report, the next report opens and the page number starts at 4.

      I found an example of this, but when I try and incorporate it, it counts each line on the page as a page so instead of saying Page 1, it says Page 25 (the number of lines on the page is 24). I cannot figure it out.

      Code:
      (pagenumberfunctions)
      
      Option Compare Database
      
      Dim PageNumber As Integer
      Sub initPageNums()
       PageNumber = 0
      End Sub
      Function GetPageNumbers() As Integer
       PageNumber = PageNumber + 1
       GetPageNumbers = PageNumber
      End Function
      That is my code in a module called pagenumberfunct ions.

      On the first report, on open, I call initPageNums as an event.
      I then have an unbound text box in the page footer that has a control source of
      =GetPageNumbers ()

      But like I said it displays 25 instead of 1, 25 being the number of lines on the page + 1. Why would it count each line as a seperate page?
      1. In Standard Code Module:
        [CODE=vb]Public lngPageNumber As Long[/CODE]
      2. Create a Text Box in all Page Footers in all Reports named txtPageNum.
      3. Initialize Public Variable in the Open() Event of the "1st" Form only:
        [CODE=vb]lngPageNum = 0[/CODE]
      4. Place the following code in the Format() Event of all Report Page Footers:
        [CODE=vb]
        Private Sub PageFooterSecti on_Format(Cance l As Integer, FormatCount As Integer)
        lngPageNumber = lngPageNumber + 1
        Me![txtPageNum] = "Page Number: " & lngPageNumber
        End Sub[/CODE]

      Comment

      • bhughes2187
        New Member
        • Mar 2008
        • 32

        #4
        Originally posted by ADezii
        1. In Standard Code Module:
          [CODE=vb]Public lngPageNumber As Long[/CODE]
        2. Create a Text Box in all Page Footers in all Reports named txtPageNum.
        3. Initialize Public Variable in the Open() Event of the "1st" Form only:
          [CODE=vb]lngPageNum = 0[/CODE]
        4. Place the following code in the Format() Event of all Report Page Footers:
          [CODE=vb]
          Private Sub PageFooterSecti on_Format(Cance l As Integer, FormatCount As Integer)
          lngPageNumber = lngPageNumber + 1
          Me![txtPageNum] = "Page Number: " & lngPageNumber
          End Sub[/CODE]

        Thanks! I'll give this a try. Was planning on scrapping the original thought and trying to figure out a better way of doing it.. Appreciate it much!


        edit: You are FABULOUS!!! That works, thanks

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by bhughes2187
          Thanks! I'll give this a try. Was planning on scrapping the original thought and trying to figure out a better way of doing it.. Appreciate it much!


          edit: You are FABULOUS!!! That works, thanks
          You are quite welcome.

          Comment

          Working...