Results 1 to 5 of 5
  1. #1
    crockegg is offline Novice
    Windows 11 Access 2016
    Join Date
    Oct 2023
    Posts
    1

    Can I put a SUM TOTAL of the specific data generated in the detail section at the HEADER of report.


    Hello, I want to create a SUM expression in the header section of my report using data from an expression that was generated in the detail section of the page however it doesn't seem to work and instead displays #Error. The SUM expression in the header is an attempt at a summary or total of what I am generating in the detail section below but I'm not getting the results I want, possibly because the Access program runs the header expression before the one in the detail section? but I need it to be the other way around.

    In simpler terms, is there a way I can put a TOTAL of the data generated in the detail section of the report at the header of the page?

    P.S. I can't seem to use the group, sort, and total tool because it's only for data that was originally from an existing field, not a new one generated on the report itself such as this.

    Appreciate the Help!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Yes, how can you sum something when it has not been generated? Sum in the footer in a hidden control and refer to that control in your header control.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You certainly can sum a bound detail control inside of a header so there's that. Can't recall if you can do that with an unbound detail section control.
    It would help to know what the data and expressions look like and what the expected result is.
    Perhaps you can solve this with a hidden textbox in the detail section and set the running sum property, then in the header, refer to the hidden control.
    EDIT - forgot to mention that perhaps your problem is that the header control is trying to sum an unbound calculated control in the detail section?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Aggregate functions cannot reference controls, only fields.

    If I remember right, aggregate functions won't work in Page header/footer, just Report and Group header/footer sections. And just referencing a group or report header/footer textbox will not provide page total - but reference textbox if you want a REPORT total on each page. If you really want a PAGE total - that requires VBA code. https://answers.microsoft.com/en-us/...c-014c06374408

    Here is sample from my report:
    Code:
    Option Compare Database
    Option Explicit
    Public intPageCount As Integer
    Public intPageTotal As Integer
    
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
       ' increment intPageCount and intPageTotal for each record printed
        intPageCount = intPageCount + 1
        intPageTotal = intPageTotal + Nz(Me!Qty, 0)
    End Sub
    
    Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
        'set the textboxes in footer
        Me.tbxPageCount = intPageCount
        Me.tbxPageTotal = intPageTotal
        'reset our counters
        intPageCount = 0
        intPageTotal = 0
    End Sub
    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can have a textbox with

    =Sum(FieldName)

    in the report header. You'll get an error in the page header/footer.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 05-15-2020, 04:56 PM
  2. Report cancel on no data in detail section
    By caniread in forum Reports
    Replies: 1
    Last Post: 02-21-2016, 07:08 AM
  3. Replies: 6
    Last Post: 12-14-2015, 03:25 PM
  4. Replies: 4
    Last Post: 11-16-2015, 08:15 AM
  5. Replies: 6
    Last Post: 03-26-2013, 12:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums