Solved

Unable to set the Text property of the ChartTitle class

Posted on 2014-03-25
5
1,031 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 52

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

615 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