Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1983
  • Last Modified:

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

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
lizziesboy
Asked:
lizziesboy
  • 5
  • 5
  • 4
1 Solution
 
telyni19Commented:
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
 
lizziesboyAuthor Commented:
That gives me the error "application-defined or object-defined error".
0
 
telyni19Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
lizziesboyAuthor Commented:
I still get "object does not support this property or method" when I try that.
0
 
telyni19Commented:
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
 
lizziesboyAuthor Commented:
it is bombing at the line
        .OneColorGradient msoGradientHorizontal, Variant:=1, Degree:=0.3
Without that line the color change works.
0
 
Jeffrey CoachmanCommented:

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
 
Jeffrey CoachmanCommented:
I guess that there is a reason why you cant do this in the chart options dialog box?
0
 
Jeffrey CoachmanCommented:
Check your syntax, you forgot the ".Fill"


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



0
 
lizziesboyAuthor Commented:
It turns out that my copy of access needed to be repaired. I'm going to split the points among all of you.
0
 
telyni19Commented:
Thanks for the points, but I thought you were planning on splitting them?
0
 
Jeffrey CoachmanCommented:
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
 
telyni19Commented:
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
 
Jeffrey CoachmanCommented:
;-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now