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
Dave - 02 Nov 2006 04:01 GMT
You just need to trap the error. If it only errors out when there's no data,
simply show a message box with words of that nature.
Try this:
On Error Goto ErrorHandler
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
ExitPoint:
Exit Sub
ErrorHandler:
Select Case err.number
Case 1004
Msgbox “There is no data available”
Case else
Msgbox err.number & “: “ err.description
End select
Resume ExitPoint
Hope that was of some help.
Dave
> 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
[quoted text clipped - 21 lines]
> Next
> End With