Hi,
I'm new to this forum and I would appreciate any help with the following issue:
Via VBA I have access to the seriescollection of a pie chart on a form, but when copying the pie chart (including code) to a report I get a run time error 438 'Object does not support this property or method'
CODE START:
Sub SetColor(InspType As String)
Dim pReport As Report '<=================== OR FORM
Dim c As Control 'Object '<=================== OBJECT OR CONTROL MAKES NO DIFFERENCE (?)
Dim sSQL As String
Dim rst1 As DAO.Recordset
Dim MySeries As Series
On Error GoTo Handle_Error
Set pReport = Report_R_IRReason '<============= REFERENCE TO FORM WHEN CHART ON FORM
'Loop through all the controls in this report and pickout all the graphs
For Each c In pReport.Controls
'Graphs initially appear to be in an Object Frame
If TypeOf c Is ObjectFrame Then
'Check the Class of the object to make sure its a Chart
If Left$(c.Class, 13) = "MSGraph.Chart" Then
With c.SeriesCollection(1) '<================================ ERROR WHEN REPORT, OKAY WHEN FORM
'.Border.ColorIndex = 19 'edges of pie shows in white color
For j = 1 To .Points.Count
With .Points(j)
.ApplyDataLabels xlDataLabelsShowLabel
If .DataLabel.Caption = InspType Then
sSQL = "SELECT ChartColor FROM T_InspTypes WHERE InspType='" & InspType & "';"
Set rst1 = CurrentDb.OpenRecordset(sSQL, dbOpenSnapshot)
If rst1.RecordCount = 1 Then
MsgBox InspType & ", color:" & rst1.Fields(0)
End If
rst1.Close
Set rst1 = Nothing
End If
.ApplyDataLabels xlDataLabelsShowPercent
'.ApplyDataLabels xlDataLabelsShowLabelAndPercent
End With
Next
End With
End If
End If
Next
Exit_Process:
Exit Sub
Handle_Error:
MsgBox "R_IRReason_Sub SetColor: " & Err.number & vbCrLf & Err.Description
Resume Exit_Process
End Sub
CODE END
So the above code works with a pie chart on a form, but gives an error when the chart is on a report.
Can somebody help as this is annoying me for days now.
Thanks.
Bert