vba 在 Microsoft Access 2010 报表中设置图表的 RowSource
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11540439/
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
Setting RowSource of a Chart in a Microsoft Access 2010 Report
提问by Friend of Kim
I have chart inside a report in Microsoft Access 2010 that gets its RecordSource via VBA in the OnLoad of the report. The reason is that I have a form where the user can select what to include in the report. So the query that is set in VBA is
我在 Microsoft Access 2010 中的一个报表中有图表,它通过报表的 OnLoad 中的 VBA 获取其 RecordSource。原因是我有一个表单,用户可以在其中选择要包含在报告中的内容。所以在 VBA 中设置的查询是
Me.Chart01.RowSource = "xxxx WHERE tbl_cars.ID In (" & IDs & ");"
Me.Chart01.Requery
DoCmd.Requery
The problem is that the graph does not update. After doing MsgBox Me.Chart01.RowSource
both before and after where I set the RowSource, the SQL seems to be correct. It works perferctly when I remove the In() part and try it in the Query Design.
问题是图表没有更新。在MsgBox Me.Chart01.RowSource
我设置 RowSource 之前和之后都做了之后,SQL 似乎是正确的。当我删除 In() 部分并在查询设计中尝试它时,它可以完美地工作。
(I load the RecordSource of the report the same way, and it works.)
(我以相同的方式加载报告的 RecordSource,并且它有效。)
Are the charts in Access too poor to be able to do this, or is there a solution to this problem?
Access 中的图表是否太差而无法执行此操作,或者是否有解决此问题的方法?
采纳答案by KFleschner
Reports don't refresh like forms, so if the chart is unbound you'll have to take care and place the code changing the row source in an event which occurs before the report is rendered like the Format or Print event. I'm assuming the IDs you're including in the SQL string are numeric and not strings.
报告不像表单那样刷新,因此如果图表未绑定,您必须小心并将更改行源的代码放置在一个事件中,该事件发生在报告呈现之前,如格式或打印事件。我假设您在 SQL 字符串中包含的 ID 是数字而不是字符串。