Access 2007 VB Runtime Error 6

I have this code in a report. It worked perfectly last I used it about 6 months ago and now I'm getting a Run-time Error 6 (Overflow) and don't really know why. The report shows a list of the status of personnel packets from a department. The code is supposed to calculate a percentage of packets received as opposed to not received, and color-code a pie graph at the foot of the page, with a total between all departments at the report footer. The code now overflows at line 8 [NotRec = (...]  I have tried to change the variable types around to some extent, but I'm stull not sure why it worked a few months ago and now it doesn't. Any ideas. I have also included a view of what the report is supposed to look like. There were never any issues with a 100% status, either.

 
Option Compare Database
Option Explicit

Private Sub GroupFooter0_Format(Cancel As Integer, FormatCount As Integer)
Dim chrt As Object
Dim strCat As String
Dim NotRec As Double
 NotRec = ((DCount("*", "PER FILTER E5", "KeyStatus='NotReceived'" & "AND UPC=" & "'" & [UPC] & "'")) / (DCount("*", "[PER FILTER E5]", "UPC=" & "'" & [UPC] & "'")))

Set chrt = Me.Graph11
    If NotRec = 1 Then
        'All red for NotReceived
        chrt.SeriesCollection(1).points(1).Interior.Color = 255
    Else
        chrt.SeriesCollection(1).points(1).Interior.Color = 32768
    End If

End Sub


Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
Dim chrt As Object
Dim strCat As String

Set chrt = Me.Graph26
    If Me.Text32 = 1 Then
        'All red for NotReceived
        chrt.SeriesCollection(1).points(1).Interior.Color = 255
    Else
        chrt.SeriesCollection(1).points(1).Interior.Color = 32768
    End If

End Sub

Open in new window

PER-REPORT.pdf
LVL 1
USArmy1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mbizupConnect With a Mentor Commented:
Written a little more cleanly:

Private Sub GroupFooter0_Format(Cancel As Integer, FormatCount As Integer)
Dim chrt As Object
Dim strCat As String
Dim NotRec As Double
dim lngCount as Long

LngCount = DCount("*", "[PER FILTER E5]", "UPC=" & "'" & [UPC] & "'")
if lngCount = 0 then lngCount = 1

 NotRec = ((DCount("*", "PER FILTER E5", "KeyStatus='NotReceived'" & "AND UPC=" & "'" & [UPC] & "'")) / lngCount))



Note that I am using 1 as a substitute for Zero.  You may need to alter that, but the point is that you can't divide by zero (BLUF)
0
 
mbizupCommented:
USArmy1,

The issue is most likely that the DCount statement is resulting in a zero (causing a floating point overflow when used in division).

Try changing:
DCount("*", "[PER FILTER E5]", "UPC=" & "'" & [UPC] & "'")

To:

iif(DCount("*", "[PER FILTER E5]", "UPC=" & "'" & [UPC] & "'") = 0, 1, DCount("*", "[PER FILTER E5]", "UPC=" & "'" & [UPC] & "'"))
0
 
USArmy1Author Commented:
Thanks mbizup! It's getting past the overflow now, but I'm getting a 1004 Error (Unable to get the SeriesCollection property of the chart class) at 15 (after the "Else").
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
USArmy1Author Commented:
Nevermind. I didn't see your second post. That seems to work! Thanks a million!
0
 
mbizupCommented:
Okay -

I'm trying to understand your data at this point.  What do you want to happen for cases where (DCount("*", "[PER FILTER E5]", "UPC=" & "'" & [UPC] & "'") = 0 ?


(ie: cases where there are NO records in in [PER FILTER E5] where UPC is the specified code)
0
 
mbizupCommented:
I'm a little slow today :)

Glad that worked out for you.
0
 
USArmy1Author Commented:
Hmmm. The report is functioning, but the graph is not producing the right numbers...

If I understand your question correctly (which I probably don't) a UPC should not show up that has no records. The primary key of the query is the person (SSN, actually) and each person is assigned to a UPC. The report is sorted with one UPC on each page...
0
 
mbizupCommented:
USArmy1,

Would you be able to post a sample copy of the database -- just the form, tables etc needed to reproduce this  -- so that I can get a better idea of what is happening?

Your data is clearly sensitive, so ensure that any sample you post is using junk data
0
 
mbizupCommented:
<< If I understand your question correctly (which I probably don't) a UPC should not show up that has no records. >>

It sounds like you're understanding my point perfectly.  The issue from what I can tell is that the UPC on the report does not have any corresponding records in your [PER FILTER E5] table or query, and that caused the divide by zero (overflow) error.

General debugging tip - add a message box to let you know which UPC values are causing this problem:

Private Sub GroupFooter0_Format(Cancel As Integer, FormatCount As Integer)
Dim chrt As Object
Dim strCat As String
Dim NotRec As Double
dim lngCount as Long

LngCount = DCount("*", "[PER FILTER E5]", "UPC=" & "'" & [UPC] & "'")
if lngCount = 0 then lngCount = 1
if lngcount = 0 then msgbox "UPC = " & [UPC]   '<--- add this

Open in new window


Does anything about that UPC or the data in your query or table seem unusual for that record?  (you are the judge of that)

If it the data looks okay, what do you want to have happen in your report?  "NotRec" will be zero for these cases.  

You have a special case in your code for NotRec = 1.

Do you need a special case for NotRec = 0 as well?

0
 
USArmy1Author Commented:
Thanks for the tip! I'll start doing that.

While creating the dummy database, I actually figured out what the second issue was. The code works fine, but the chart was querying the wrong dataset on the property sheet, so the colors were showing correctly per the code, but numbers were wrong. Good to go there. Now...the only issue is that the color coding isn't working. It works on the report footer (the overall percentage for all UPCs) but in the report, everything is red regardless.

...and now it seems the report footer is backwards. Odd...I think it was right in the original DB.
DUMMYperDB.accdb
0
 
mbizupCommented:
Okay - I will check this out on my Access 2007 machine this evening (US East Coast)
0
 
mbizupCommented:
It didn't look like your code was running at all in the sample.

Try placing your code in the Group Footer Print event instead of the Format event.

This made both colors show up for me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.