Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Mar 2004
    Location
    White Oak, Pennsylvania, USA
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have an Access report that keeps a running total (by code) of elapsed times (sngTimeElapsed).

    sngTimeElapsd = sngTimeElapsd + Me.TaskTime

    Then in the Report Footer, I print out the total in a text box.

    Me.txtWeekTotal = sngTimeElapsd

    In print preview, the total is correct. When I actually print out the report, the total is doubled.
    I've tried both the OnPrint Event and the OnFormat Event to place this data on the report and neither works properly on actual printout.

    Can you help me with this, please?

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    I think we need to see a simplified version of your database with some sample data so we can see how the report is constructed. Is the calculation being done in a query which is the data source for the report, or is that being done is some code being run on one of the report events? And what code are you trying to run on the OnPrint or OnFormat events? With a sample, we can answer those questions.
    Wendell

  3. #3
    Star Lounger
    Join Date
    Dec 2009
    Location
    Bellevue, WA
    Posts
    61
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Have you tried using =Sum(TaskTime) in the report footer?

  4. #4
    Star Lounger
    Join Date
    Mar 2004
    Location
    White Oak, Pennsylvania, USA
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wendell,

    All calculations are done in the report. The report is based on a query that allows the operator to specify a data range.

    The code for the Detail_Print sub is shown below. I add the task time to the elapsed time (declared variable as single for the entire report) in this section of the report
    -------------------------
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

    Me.txtTaskTotal = Me.txtTaskTotal + Me.TaskTime
    Me.txtDayTotal = Me.txtDayTotal + Me.TaskTime
    sngTimeElapsd = sngTimeElapsd + Me.TaskTime

    End Sub
    -----------------------
    Then, in the report footer, I have this code:
    -------------------------
    Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As Integer)

    Me.txtWeekTotal = sngTimeElapsd

    End Sub
    ----------------------------

    When the report is printed in preview mode, the totals for the entire report are correct in the report footer. However, if the user subsequently requests a hard copy printout, the totals are doubled. All the detail sections are correct, only the report totals are doubled.

    Perhaps there is a better way to accumulate the total time over the report. I've tried running sums for the TaskTime data field to no avail.

    Thanks for the help.

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    I think the issue you are encountering is because you are doing a Print Preview first, and then the print, and the value of sngTimeElapsd is not being set to zero. Both of the routines get run again when you print. Have you tried printing directly rather than going to Print Preview and then Printing?

    In any event, I don't see any need for doing these calculations in code. As Larry suggested in his response, you can use the Sub function in a control to add up the values and display them in a footer, or in a group footer. My take on these sort of things is to only use code if I can't do it using the built-in features, and this (Sum()) is one that is very powerful when it comes to doing reports.
    Wendell

  6. #6
    Star Lounger
    Join Date
    Mar 2004
    Location
    White Oak, Pennsylvania, USA
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, printing the report directly to the printer works fine.

    I have never had much luck with the Sum() function. I'll attempt to use the Sum() function - thanks.

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    You can fix this via code by testing for the value of PrintCount.

    If PrintCount =1 then

    before the code that increments the values.
    Regards
    John



Posting Permissions

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