run-time error 1004 unable to set the seriescollection property"

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
 
D

Dave

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
 

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