vba 在 Access 中嵌入生成的 Excel 图表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14895659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:37:29  来源:igfitidea点击:

Embed a generated Excel chart in Access

excelvbams-access

提问by matcauthon

The appearance of the ordinary charts widget of MS Access 2010 is not very attractive.

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

Is it possible (and how?) to embed the rather attractive Excel charts in Access and fill them with data from a query (dynamically)?

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

PS:

PS:

Because I want to update the chart depending on user input the use of pivot-charts is not possible.

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

采纳答案by Fionnuala

Some notes on using a chart

使用图表的一些注意事项

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

Two other approaches using a similar set up with a subform.

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

/1. Use link child and master fields

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

The link master fields are set to the names of the listbox controls and the link child fields are set to the relevant fields for the chart:

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

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

Clicking the relevant control redraws the chart.

单击相关控件可重新绘制图表。

chart

图表

/2. Use a query and force a redraw:

/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