Solved

Unable to set the Text property of the ChartTitle class

Posted on 2014-03-25
5
974 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 50

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

830 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