Link to home
Start Free TrialLog in
Avatar of USArmy1
USArmy1Flag for United States of America

asked on

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
Avatar of mbizup
mbizup
Flag of Kazakhstan image

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] & "'"))
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of USArmy1

ASKER

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").
Avatar of USArmy1

ASKER

Nevermind. I didn't see your second post. That seems to work! Thanks a million!
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)
I'm a little slow today :)

Glad that worked out for you.
Avatar of USArmy1

ASKER

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...
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
<< 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?

Avatar of USArmy1

ASKER

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
Okay - I will check this out on my Access 2007 machine this evening (US East Coast)
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.