• Doubling of sums

    Author
    Topic
    #472573

    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?

    Viewing 5 reply threads
    Author
    Replies
    • #1251958

      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.

    • #1251991

      Have you tried using =Sum(TaskTime) in the report footer?

    • #1252014

      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.

    • #1252036

      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.

    • #1252077

      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.

    • #1252315

      You can fix this via code by testing for the value of PrintCount.

      If PrintCount =1 then

      before the code that increments the values.

    Viewing 5 reply threads
    Reply To: Doubling of sums

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

    Your information: