run-time error 1004 unable to set the

M

Mike C

I'm using vb to format a pie chart in my access report. it works fine when
there's data but i get the error "run-time error 1004 unable to set the
seriescollection property" when there's none. Does anyone know how I can
modify my code to handle this? The code is below. Thanks!!

Dim myChart As Graph.Chart
Set myChart = Me.myChart.Object

myChart.Refresh
myChart.Application.Update

With myChart.SeriesCollection(1)
For i = 1 To .Points.Count
Select Case myChart.Application.DataSheet.Cells(i + 1, 1).Value
Case "AAA"
.Points(i).Interior.ColorIndex = 3 ' Red
Case "BBB"
.Points(i).Interior.ColorIndex = 6 ' Yellow
Case "CCC"
.Points(i).Interior.ColorIndex = 4 ' Green
Case Else
.Points(i).Interior.ColorIndex = 5 ' Blue
End Select
Next
End With
 
M

Mike C

The report is actually a subReport, so what's happening is that, even though
the subreport's data source has no null values when run by itself in
isolation, it does have null when the subreport is run as part of the main
report. There's way too much data in the main report to add Null values. Any
additional suggestions would be great. Thanks for your reply!
 
N

NetworkTrade

ok you can't change the table nulls to 0 - that would have been one approach.

One doesn't know what you want to occur with the chart when the field is
null....but in your code below it assumes a value for
myChart.SeriesCollection with the Case Select.....so maybe you need to add
before this Case Select code some If/Then code for if
myChart.SeriesCollection Is Null.....
 
M

Mike C

Thanks for the suggestion. I actually tried that before making my post. It's
a great idea conceptually but I'm not sure how to actually write the code. I
tried the following code but receive a "Run-Time error '424' Object Required."

If MyChart.SeriesCollection(1) Is Not Null Then
With MyChart.SeriesCollection(1)
For i = 1 To .Points.Count
Select Case MyChart.Application.DataSheet.Cells(i + 1, 1).Value
Case "AAA"
.Points(i).Interior.ColorIndex = 3 ' Red
Case "BBB"
.Points(i).Interior.ColorIndex = 6 ' Yellow
Case "CCC"
.Points(i).Interior.ColorIndex = 4 ' Green
Case Else
.Points(i).Interior.ColorIndex = 5 ' Blue
End Select
Next
End With
End If
 
M

Mike C

I think I need to say something along the lines of, "If there is an object
present, Then execute the code". Any thoughts on how to write that? Thanks!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top