excel - 在 Access 中嵌入生成的 Excel 图表

标签 excel vba ms-access

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

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

附言:

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

最佳答案

使用图表的一些注意事项

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

关于excel - 在 Access 中嵌入生成的 Excel 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14895659/

相关文章:

excel - 仅使用不使用宏的公式从 Excel 单元格内获取行号和列号

xml - 在 VBA 中解析 XML 响应数据

excel - 根据单元格值对行求和,然后删除所有重复项

excel - 有没有关于如何在Excel中通过VBA驱动Office "Equation Editor"的文档?

excel - 如何使用VBA将excel中的单元格值循环到网站文本框中?

docker - 如何在 Docker 容器上安装 Access Runtime?

vb.net - 添加多个文本框.net

excel - 导入excel文件对现有数据返回null

c# - 查找 IEnumerable 的第一个索引

excel - 如何计算一个独特事件在 Excel 中发生的次数?