Solved

Use VBA to Change gradient style in Access 2010 report graph.

Posted on 2010-08-13
14
1,912 Views
Last Modified: 2013-11-28
I have a report in Access 2010 that contains a graph. I need to change the color and gradient effects of a data sereies programmatically. I can change the color but when I try to change the gradient I get the error "object does not support this property or method". I am using the code below. What am I doing wrong?

Private Sub Report_Load()

    Dim SummGraph As Chart

    Dim pt As ChartGroup

 

    Set SummGraph = Me.SummaryGraph.Object.Application.Chart  'initialize things to a normal look

    With SummGraph.SeriesCollection(1)

        .Interior.Color = RGB(255, 0, 0)

        .OneColorGradient msoGradientHorizontal, Variant:=1, Degree:=0.3

    End With

    

End Sub

Open in new window

0
Comment
Question by:lizziesboy
  • 5
  • 5
  • 4
14 Comments
 
LVL 12

Accepted Solution

by:
telyni19 earned 500 total points
ID: 33430417
Try
.Fill.OneColorGradient msoGradientHorizontal, Variant:=1, Degree:=0.3

Note the .Fill.
Gradient is a fill property, in other words, not directly a series property. ChartArea and other sections of the chart each have their own Fill property which can be modified with gradients.
0
 

Author Comment

by:lizziesboy
ID: 33430623
That gives me the error "application-defined or object-defined error".
0
 
LVL 12

Expert Comment

by:telyni19
ID: 33430825
According to this thread:
http://www.ozgrid.com/forum/showthread.php?t=141878&page=1

It's actually .Format.Fill for series collections. So you'd want this line instead:

.Format.Fill.OneColorGradient msoGradientHorizontal, Variant:=1, Degree:=0.3
0
 

Author Comment

by:lizziesboy
ID: 33431214
I still get "object does not support this property or method" when I try that.
0
 
LVL 12

Expert Comment

by:telyni19
ID: 33431352
Getting the properties in the right order and layer for charts in VBA is always a pain in my experience.

Which line is the error actually happening at? Is it happening at the With statement or at the Gradient statement?

I'm trying to reproduce your error and am getting a different error entirely. Of course, I don't have your setup, either.
0
 

Author Comment

by:lizziesboy
ID: 33431876
it is bombing at the line
        .OneColorGradient msoGradientHorizontal, Variant:=1, Degree:=0.3
Without that line the color change works.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33433160

Have you tried declaring the chart as an "Object"?

The thing with charts is that you will get odd errors if certain things just cant be done.

For example, you cannot "easily" get a datapoint values with the Chart Labels turned off.

Also a lot of chart objects are arrays so you may not be able to Get or Set them directly
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33433172
I guess that there is a reason why you cant do this in the chart options dialog box?
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33435112
Check your syntax, you forgot the ".Fill"


.Fill.OneColorGradient msoGradientHorizontal, Variant:=1, Degree:=0.3



0
 

Author Comment

by:lizziesboy
ID: 33436798
It turns out that my copy of access needed to be repaired. I'm going to split the points among all of you.
0
 
LVL 12

Expert Comment

by:telyni19
ID: 33466722
Thanks for the points, but I thought you were planning on splitting them?
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33467639
LOL,
telyni19, I just noticed that in your first post you noticed that "Fill" was missing.
So you get the points...
As a budding new Expert here, you could use them more than me.
;-)
Jeff
0
 
LVL 12

Expert Comment

by:telyni19
ID: 33467984
Well, and then when that didn't work, I gave a different answer that probably wouldn't have been right. I wasn't certain of the answer, only first. But I appreciate your graciousness at the outcome.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33468193
;-)
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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

706 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

16 Experts available now in Live!

Get 1:1 Help Now