Solved

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

Posted on 2010-08-13
14
1,930 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
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.

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

840 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