Dynamically change Pivot Chart title (1 Viewer)

Ipem

Registered User.
Local time
Today, 21:03
Joined
Aug 26, 2013
Messages
29
Hello all,

I am trying to change dynamically the text of the PivotChart, according to the current filter. This is a user request. The VBA code should run whenever the view is changed to pivotchart. I'm im Access 2007

This is my code so far:
Code:
Private Sub Form_AfterFinalRender(ByVal drawObject As Object)
    If Not (Me.CurrentView = acCurViewPivotChart) Then Exit Sub
    Me.ChartSpace.HasChartSpaceTitle = True
    Me.ChartSpace.ChartSpaceTitle.Caption =  Me.Filter
End Sub

This generates an error:
Runtime error '-2147467259 (80004005)':
Cannot change chart attributes in an event handler

I am stuck. Is there any way around? I have placed a button to the datasheet view of the form to take users to PivotChart view. I can change the chart title from the code of that button. But I can't prevent users from using the built in ribbon button for pivotchart view, so I need to run this code from an event.

Thx,
 

JHB

Have been here a while
Local time
Today, 21:03
Joined
Jun 17, 2012
Messages
7,732
The below works by me it is placed in the detail section's format event.
The chart name is Diagram0.

Private Sub Detaljesektion_Format(Cancel As Integer, FormatCount As Integer)
Dim Titel As String

Titel = Me.STAT_TYPE
Me.Diagram0.Charttitle.Caption = Titel
End Sub
 

Ipem

Registered User.
Local time
Today, 21:03
Joined
Aug 26, 2013
Messages
29
Thank you JHB, for your quick reply.
I can't find the event you have referred to. The format event of the detail object of the form has only click, doubleclick, mouseup, mousemove, mousedown and paint events -at least theese what I can see. Is not that a danish event name?
 

JHB

Have been here a while
Local time
Today, 21:03
Joined
Jun 17, 2012
Messages
7,732
Is not that a danish event name?
No - sorry it is a report event.

This is for a form on current event, (the chart name is Graph0).
Code:
Private Sub Form_Current()
  Me.Graph0.Object.ChartTitle.Caption = "What Ever"
End Sub
 

Users who are viewing this thread

Top Bottom