我正在拔出我的头发,试图解析数据或编辑成一个味精系列集合。
我得到了error 438 - object does not support this property or method。
我可以操作对象具有的其他属性,如ChartTitle.Font.Size,但不能操作序列化集合。
智能化在这个对象下不起作用,这使我不得不仔细考虑,我还没有设置特定的引用。
代码的部分如下。
主例程获取对象:
strReportName = "Security Selection"
strChartName = "MACD_Chart"
DoCmd.OpenReport strReportName, acViewDesign
Set rptMACD = Reports(strReportName)
Set chartMACD = rptMACD(strChartName)生成一个数据记录集,然后将所有数据记录集传递到子例程:
Call UpdateChart(chartMACD, rstMACD)
Public Sub UpdateChart(chartPlot As Object, rstChart As ADODB.Recordset)
'FUNCTION:
' a chart object is passed into the routine,
' source data is update to the recordset being passed in.
Dim lngType As Long
Dim i, j, iFieldCount As Integer
Dim rst As Recordset
Dim arXValues() As Date
Dim arValues() As Double
Dim strChartName, strYAxis, strXAxis As String
Dim ChrtCollection As ChartObjects
Dim colmCount As Integer
chartPlot.RowSourceType = "Table/Query"
'get number of columns in chart table/Query
iFieldCount = rstChart.Fields.Count
With chartPlot
'change chart data to arrays of data from recordset
.Activate
j = 0
rstChart.MoveFirst
Do While Not rstChart.EOF
j = j + 1
ReDim Preserve arXValues(1 To j)
arXValues(j) = rstChart.Fields("Date").Value
rstChart.MoveNext
Loop
For i = 1 To iFieldCount - 1 'Date is first field
j = 0
rstChart.MoveFirst
Do While Not rstChart.EOF 'get next array of data
j = j + 1
ReDim Preserve arValues(1 To j)
arValues(j) = rstChart.Fields(i + 1).Value
rstChart.MoveNext
Loop
.SeriesCollection(i).Name = rstChart.Fields(i + 1).Name
.SeriesCollection(1).XValues = arXValues
.SeriesCollection(i).Values = arValues
Next i
end sub我尝试过很多事情,现在我完全糊涂了。我也一直在尝试在记录集中进行解析(这是我的首选),但是现在我会接受任何东西。
发布于 2013-08-30 17:22:08
继续之前的Rowsource:我建议将图表的属性设置为返回所需数据的查询,然后将其设置为 Requery**ing图表。这是_的方式_比下面的更容易。**
您正在获取Error 438,因为Name, XValues, Values不是Series对象的属性。MSDN信息
尽管如此,这里是您的方法和一些建议,以这样做。SeriesCollection不像在MSGraph中那样包含与MSGraph点相关联的值。您需要编辑DataSheet中的数据,这是非常挑剔的。必须包括对Microsoft图形库的引用。对此进行了测试,以便与我的数据库一起工作。Microsoft Graph信息
DAO
Public Sub testing()
Dim rstChart As Recordset
Dim seri As Object, fld As Field
Dim app As Graph.Chart
chartPlot.SetFocus
Set app = chartPlot.Object
Set rstChart = CurrentDb.OpenRecordset("SELECT DateTime, ASIMeasured FROM Surv_ASI WHERE CycleID = 2 ORDER BY DateTime")
app.Application.DataSheet.Range("00:AA1000").Clear
With rstChart
For Each fld In .Fields
app.Application.DataSheet.Range("a1:AA1").Cells(0, fld.OrdinalPosition) = fld.Name
Next
Do While Not .EOF
For Each fld In .Fields
app.Application.DataSheet.Range("a2:AA1000").Cells(.AbsolutePosition, fld.OrdinalPosition).Value = fld
Next
.MoveNext
Loop
End With
app.Refresh
End SubADO (假设rstChart已经是有效的ADODB.Recordset)
Public Sub testing()
Dim app As Graph.Chart, i As Integer
chartPlot.SetFocus
Set app = chartPlot.Object
app.Application.DataSheet.Range("00:AA1000").Clear
With rstChart
.MoveFirst 'Since I don't know where it was left off before this procedure.
For i = 0 To .Fields.Count - 1
app.Application.DataSheet.Range("a1:AA1").Cells(0, i) = .Fields(i).Name
Next
Do While Not .EOF
For i = 0 To .Fields.Count - 1
app.Application.DataSheet.Range("a2:AA1000").Cells(.AbsolutePosition, i).Value = .Fields(i)
Next
.MoveNext
Loop
End With
app.Refresh
End Sub关于我的改变的一些注意事项:
With指向被循环的记录集,而不是被操作的对象,特别是因为在您的过程中对记录集的属性进行了更多的调用。Next应用的变量(Next i)。把Next放进去。https://stackoverflow.com/questions/18460890
复制相似问题