通过VBA在Access报告中修改图表属性(错误2771) [英] Modify Chart properties in Access report via VBA (error 2771)

查看:554
本文介绍了通过VBA在Access报告中修改图表属性(错误2771)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个Access报告(2010版),并希望能够根据用户在表单上的选择进行自定义。当我运行它,我得到错误2771:试图编辑的绑定或未绑定的对象框架不包含OLE对象。

I am building an Access report (2010 version), and would like to be able to customize it based on the user's selections on a form. When I run it, I get error 2771: The bound or unbound object frame you tried to edit does not contain an OLE object.

这是传递参数的代码:

Private Sub Command120_Click()
    DoCmd.OpenReport ReportName:="rpt_EODGraph", View:=acViewPreview, _
      OpenArgs:=Me!Text0.Value
End Sub

代码打开报告。

Private Sub Report_Open(Cancel As Integer)
    Dim ch As Chart
    Set ch = Me.Graph3.Object.Application.Chart 'This line generates the error
    ch.ChartTitle.text = OpenArgs
End Sub

我发现至少有一个人说这是不可能在报告上做的。 ( http://www.access-programmers。 co.uk/forums/showthread.php?t=177778&page=2 请注意,这是2页论坛讨论的第2页...)任何人都可以证实或反驳?

I've found at least one person saying that this is not actually possible to do on a report. (http://www.access-programmers.co.uk/forums/showthread.php?t=177778&page=2 Note that this is page 2 of a 2 page forum discussion...) Can anyone corroborate or refute?

推荐答案

显然,在OLE对象可访问之前,报表必须有某种焦点。
如果您点击它或将焦点设置为某些东西就足够了:

Apparently the Report has to have some kind of focus before OLE objects are accessible. It is enough if you click on it or set the focus to something:

Private Sub Report_Open(Cancel As Integer)
    Dim ch As Object
    Me.RandomButton.SetFocus
    Set ch = Me.Diagramm11.Object
    ch.ChartTitle.Text = "Hello"    
End Sub

这样工作。我只是在获取焦点的报告上设置了一个按钮。也许你会发现更优雅的东西;)

This works. I just set a button on the report that gets the focus. Perhaps you find something more elegant ;)

这篇关于通过VBA在Access报告中修改图表属性(错误2771)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆