Solved

Unable to set the Text property of the ChartTitle class

Posted on 2014-03-25
5
928 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 48

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now