Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unable to set the Text property of the ChartTitle class

Posted on 2014-03-25
5
Medium Priority
?
1,052 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 2000 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

721 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