Gradient Shading In Charts

TimTDP

Registered User.
Local time
Today, 17:51
Joined
Oct 24, 2008
Messages
213
Public Function CreateChart(ReportName As String, ChartObjectName As String)

Dim Rpt As Report
'Dim grphChart As Object
Dim grphChart As Graph.Chart
Dim msg As String, lngType As Long, cr As String
Dim ctype As String, typ As Integer, j As Integer
Dim recSource As String
Dim colmCount As Integer, chartType(1 To 6) As String
Dim lngTwisp As Long

lngTwisp = 567 'cm

DoCmd.OpenReport ReportName, acViewDesign

Set Rpt = Reports(ReportName)

Set grphChart = Rpt(ChartObjectName).Object

grphChart.Activate
.ChartArea.Fill.Visible = msoTrue
.ChartArea.Fill.TwoColorGradient pubChartAreaFillColourGradientShadingStyle, 1
.ChartArea.Fill.ForeColor.SchemeColor = rgb(0, 0, 255)
.ChartArea.Fill.BackColor.SchemeColor = rgb(255, 0, 0)

.ChartArea.Fill.ForeColor.SchemeColor = rgb(0, 0, 255) gives me a run time error 1004 - Application defined or Object defined error

What is wrong?
 
Access 2010
 
I have a chart in an Access report.
I want to allow users to change the gradient fill of the chart are. So, they can select the fore and back colours and gradient type from combo box's on a form and the vba code will do the rest
 
.ChartArea.Fill.ForeColor.SchemeColor = rgb(0, 0, 255)
 
TimTDP

No offence intended but I think you need to stop and think about this a little more.

You seem to have many posts on AWF and UA that imply you are at the walking stage.
Again, no offence intended because we were all at that stage at some point in time.
But taking on charts in Access is more like running through molasses rather than walking through air.

So I’m going to suggest a different method of tackling the problems you are having.

Try to keep it simple.
Break the code into manageable chunks.
Test each chunk.
Remove everything not necessary.
Keep it clean.
If you get something to work, remove the junk till it stops working.
Then only add back in that which is required to get it working again.
Try to specify only those things that you need and trash the rest.
The Mona Lisa does not need a beard; if in doubt, leave it out.
Try to name things correctly; you are not creating a chart you are modifying a chart.
Try to make your questions on the web succinct. A succinct question often has its own answer.

An example of what your code currently does: -
Code:
Option Explicit
Option Compare Text


Private Sub TestIt()

    ModifyChart strReportName:="rptMyReport", _
                strChartName:="chtTestChart"

End Sub


Public Sub ModifyChart(ByVal strReportName As String, _
                       ByVal strChartName As String)
    
    Dim objThisChart As Object
    
    DoCmd.OpenReport ReportName:=strReportName, _
                     View:=acViewDesign
    
    Set objThisChart = Reports(strReportName)(strChartName).Object
    
    ModifyGradientFill objChart:=objThisChart
    
 [color=green]'  Modify Something Else
 '  Modify Something Else
 '  Modify Something Else

 '  DoCmd.Close ObjectType:=acReport, _
                ObjectName:=strReportName, _
                Save:=acSaveYes[/color]

End Sub


Private Sub ModifyGradientFill(ByRef objChart As Object)

    With objChart.ChartArea.Fill
        .ForeColor.SchemeColor = 5                  [color=green]' Blue[/color]
        .BackColor.SchemeColor = 3                  [color=green]' Red[/color]
        .TwoColorGradient msoGradientHorizontal, 1  [color=green]' msoGradientHorizontal = 1[/color]
    End With

End Sub
That is not the answer, it’s only a beginning.
It does not address the RGB colour issue. I think you will need a SchemeColor colour picker for that.
(No I don’t have one but it’s doable.)
It does not address the issue of opening a Report in Design mode which you will not be able to do if it’s a compiled file.
(It would need to be done by passing an OpenArgs list from the Form to the Report and call the ModifyChart Sub from the Report Detail_Format event.

------------------------------------------

But the overall idea is to reduce the code to clean, manageable chunks and to be able to test each chunk separately.

Chris.
 

Users who are viewing this thread

Back
Top Bottom