在Access中嵌入生成的Excel图表

时间:2013-02-15 13:18:53

标签: excel vba ms-access

MS Access 2010的普通图表小部件的外观不是很吸引人。

是否有可能(以及如何?)在Access中嵌入相当有吸引力的Excel图表并用查询中的数据(动态)填充它们?

PS:

因为我想根据用户输入更新图表,所以无法使用数据透视图。

1 个答案:

答案 0 :(得分:2)

关于使用图表的一些注意事项

Sub OpenMyChart()
''You could do this part without code, but let use say you want VBA
sSQL = "SELECT Table1.AText AS ACategory, Table1.ANumber AS AData, " _
     & "Table1.ADate AS AFilter, Table1.ATime AS ASeries " _
     & "FROM Table1 WHERE Table1.ADate=#1/20/2012#"

''This is the query that my Chart form uses
CurrentDb.QueryDefs("Chart").SQL = sSQL

''You can use a Where statement for opening the form, too
DoCmd.OpenForm "Chart", acFormPivotChart, , "ACategory='Bob'"
End Sub

使用与子表单类似的设置的另外两种方法。

/ 1。使用链接子和主字段

链接主字段设置为列表框控件的名称,链接子字段设置为图表的相关字段:

Link Master Field: List1;List2
Link Child Field: AFilter;ACategory

单击相关控件会重绘图表。

chart

/ 2。使用查询并强制重绘:

Private Sub List1_Click()
sSQL = "SELECT Table1.AText AS ACategory, Table1.ANumber AS AData, " _
     & "Table1.ADate AS AFilter, Table1.ATime AS ASeries " _
     & "FROM Table1 WHERE Table1.ADate=#" _
     & Format(Me.List1, "yyyy/mm/dd") & "#"1/13/2013#"

''This is the query that my Chart form uses
CurrentDb.QueryDefs("Chart").SQL = sSQL

''Chart is the name of the subform control, and confusingly, 
''the name of the embedded form.
Me.Chart.SourceObject = "Chart"
End Sub