We help IT Professionals succeed at work.

MS Access Report first record on new page being counted twice.

692 Views
Last Modified: 2012-05-30
I have a report that I'm using to determine on-time delivery percentage.  What I'm doing is subtracting the Required by Date by the Actual Finish date.  I then have an icount variable that i increment by 1 when the subtraction listed above equals zero or higher (indicating the trailer was delivered on time).  The problem I'm having is that for some reason the first record on a new page is being "looked at" twice...so if the subtraction is zero or greater it's being counted twice.  This is obviously affecting my percentage calculation.  Here is my code (in the detail section)

Option Compare Database
Option Explicit

Private iCount As Integer

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)


    If Nz(Me.txtMustHave.Value, 0) = 0 Or Nz(Me.txtActualFinDate.Value, 0) = 0 Then
        Me.txtPromiseDelivery.Value = Null
    Else
        Me.txtPromiseDelivery.Value = DateDiff("d", Nz([FinCompleteDate], 0), Nz([RequiredBy], 0))
    End If

    If Me.txtPromiseDelivery.Value >= 0 Then
        iCount = iCount + 1            
    End If    

End Sub

Private Function getOTDCount() As Double
    getOTDCount = iCount
End Function

Open in new window


In the Report Footer section of my report I have a text box doing the % calculation with the control source set to: =getOTDCount()/Count([JobNo])

Has anyone run into this problem before?  How can I fix this?  Or is there a better way to do what I'm attempting to do here?  

Thanks!
Comment
Watch Question

President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
If you have Page of Pages at the footer of your report, the report will force the Format event to fire twice.  You can delete this if you don't need it.

You could also put your code in the OnPrint event instead which will only fire once even with a page count in your report.

Or you could add this to the beginning of your code in the OnFormat event:
   Static z As Integer
   If z > 0 Then Exit Sub Else z = z + 1
   'rest of code goes here...
CERTIFIED EXPERT
Top Expert 2016

Commented:

Author

Commented:
Thank you everyone!  I will read those articles cap..thanks.
Jim Dettman (EE MVE)President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

Commented:
Just to clear up what IrogSinta said:

"If you have Page of Pages at the footer of your report, the report will force the Format event to fire twice.  You can delete this if you don't need it."

 This is something different, which is two-pass printing.  If you reference the pages property in your report, the report engine will do two passes through the entire report.

 In the first pass, it runs through the report, but does not fire the OnPrint event.  It does this to get the total number of pages.

 Then on the second pass, it fires everything and actually prints the report.

 This is an important point because it means that if you do reference pages, you need to make sure that you init your totals in the report header event, or you will see things double up.

 This is different and seperate from a section repeating because of formatting, which is what I was pointing out.

  For example, you set KeepTogether True for a footer.   Report engine runs down the page, discovers that it doesn't have room for the footer, so it retreats up the page, doesn't print all the detail and then moves to a new page and continues printing.

Jim.
CERTIFIED EXPERT

Commented:
Thanks for clearing that up, Jim.

Ron

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.