Solved

Unable to set the Text property of the ChartTitle class

Posted on 2014-03-25
5
953 Views
Last Modified: 2014-03-27
I have a form that has two combo boxes for selecting date range, an unbound textbox for chart title entry, a button to requery the chart and then change the chart title. The requery work great and the chart is updated and redrawn correctly. However, changing the title fails with the following error message: “Run-time error ‘1004’: Unable to set the Text property of the ChartTitle class” every time I try to set the chart tile. HasTitle is set to Ture. Also, the design view of the chart has a dummy title already assigned. In code I can read the dummy chart title text, but I cannot change it. I have attached an Access 2007 database that has the form and VBA code.
0
Comment
Question by:robtrue
  • 2
  • 2
5 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39955215
Hi,

Have you SetFocus on you chartTitle prior to changing the title?

Regards
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 39955696
Why change the .Text property, which does indeed require you to SetFocus to the Control you wish modify the .Text property.  I would suggest that you modify the .Value property (which is the default property for most Control types, so you don't need to explicitly specify it)

Me.ChartTitle = "someText"
Me.HasTitle = (Len(Me.ChartTitle & "") > 0)
0
 

Author Comment

by:robtrue
ID: 39955959
Tried each suggest separately. Individually they all failed. Then I tried all of suggests together, WOW!  It worked.  Below is the code segment that works.

    ' Set chart title
    With Me.graphNEOF.Object.Application.Chart
    If .HasTitle = True Then
        Me.graphNEOF.SetFocus
        On Error Resume Next
       .ChartTitle = "My new title test 1"          ' get error 438, resume with next
       .ChartTitle.Value = "My new title test 2"  ' get error 438, resume with next
       .ChartTitle.Text = "My new title test 3"    ' if the two above are tried first, this one works
        On Error GoTo 0
    End If
    End With

Without getting and skipping over the error 438, the ChartTitle cannot be set. Why this works I have no clue.

Thanks everyone for your suggestions.
0
 
LVL 11

Accepted Solution

by:
datAdrenaline earned 500 total points
ID: 39956564
Ok ... I was not clear that you were working with an actually Class (despite the fact that you said "Class" in your opening question.

I confess I thought you misspoke :-s ... (please don't take offense as none it intended!)

---

So ... assuming that you added your chart object with the Chart control of the Controls group on the Ribbon during Form design ... I have no issue with the following code:

Sub modMyGraphTitle()
    
    Dim myChart As Object
    Set myChart = Me.graphNEOF.Object
    
    With myChart
        If .HasTitle Then
        
            .ChartTitle.Text = "My Text1"
            Debug.Print .ChartTitle.Text
        
      End If
    End With
    
End Sub

Open in new window


But note that there is a .Caption property as well, and had no issue modifying that property as well.  It did overlay the .Title property in my quick test.  It seems that I would likely sync the two properties (.ChartTitle.Text and .ChartTitle.Caption) to the same text value.

Also, I had no issue with referencing the object as you did, but there really should not be a need to go that deep to reference the Chart object.

With our different experiences setting the same properties, you may be experiencing corruption of your Form object.
0
 

Author Comment

by:robtrue
ID: 39958653
Using the .Caption property works great.  The simplified code is show below. Thanks a million.

    ' Set chart title
    With Me.graphNEOF.Object.Application.Chart
    If .HasTitle = True Then
       .ChartTitle.Caption = "My new title"
    End If
    End With
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question